Monocarp had a sequence $a$ consisting of $n + m$ integers $a_1, a_2, \dots, a_{n + m}$. He painted the elements into two colors, red and blue; $n$ elements were painted red, all other $m$ elements were painted blue.

After painting the elements, he has written two sequences $r_1, r_2, \dots, r_n$ and $b_1, b_2, \dots, b_m$. The sequence $r$ consisted of all red elements of $a$ in the order they appeared in $a$; similarly, the sequence $b$ consisted of all blue elements of $a$ in the order they appeared in $a$ as well.

Unfortunately, the original sequence was lost, and Monocarp only has the sequences $r$ and $b$. He wants to restore the original sequence. In case there are multiple ways to restore it, he wants to choose a way to restore that maximizes the value of

$$f(a) = \max(0, a_1, (a_1 + a_2), (a_1 + a_2 + a_3), \dots, (a_1 + a_2 + a_3 + \dots + a_{n + m}))$$

Help Monocarp to calculate the maximum possible value of $f(a)$.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then the test cases follow. Each test case consists of four lines.

The first line of each test case contains one integer $n$ ($1 \le n \le 100$).

The second line contains $n$ integers $r_1, r_2, \dots, r_n$ ($-100 \le r_i \le 100$).

The third line contains one integer $m$ ($1 \le m \le 100$).

The fourth line contains $m$ integers $b_1, b_2, \dots, b_m$ ($-100 \le b_i \le 100$).


-----Output-----

For each test case, print one integer — the maximum possible value of $f(a)$.


-----Examples-----

Input
4
4
6 -5 7 -3
3
2 3 -4
2
1 1
4
10 -3 2 2
5
-1 -2 -3 -4 -5
5
-1 -2 -3 -4 -5
1
0
1
0
Output
13
13
0
0


-----Note-----

In the explanations for the sample test cases, red elements are marked as bold.

In the first test case, one of the possible sequences $a$ is $[\mathbf{6}, 2, \mathbf{-5}, 3, \mathbf{7}, \mathbf{-3}, -4]$.

In the second test case, one of the possible sequences $a$ is $[10, \mathbf{1}, -3, \mathbf{1}, 2, 2]$.

In the third test case, one of the possible sequences $a$ is $[\mathbf{-1}, -1, -2, -3, \mathbf{-2}, -4, -5, \mathbf{-3}, \mathbf{-4}, \mathbf{-5}]$.

In the fourth test case, one of the possible sequences $a$ is $[0, \mathbf{0}]$.

Source: codeforces | Difficulty: EASY
Tags: Dynamic programming

Greedy algorithms


Solutions:
t = int(input())
for _ in range(t):
	n = int(input())
	reds = list(map(int, input().split()))
	m = int(input())
	blues = list(map(int, input().split()))
	prefix_red = [0]
	prefix_blue = [0]
	for red in reds:
		prefix_red.append(prefix_red[-1] + red)
	for blue in blues:
		prefix_blue.append(prefix_blue[-1] + blue)
	print(max(prefix_red) + max(prefix_blue))


from sys import *
ws = lambda : map(int, stdin.readline().strip().split())
li = lambda : list(map(int, stdin.readline().strip().split()))
mod = 1000000007

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def prod(l):
	ans = 1
	for i in range(len(l)):
		ans = ans * l[i]
	return ans

def sortindex(l, a):
	c = []
	if a == -1:
		rev = True
	else:
		rev = False
	for i in range(len(l)):
		c.append([l[i], i])
	x = sorted(c, reverse=rev)
	print(x)
	c = []
	for i in range(len(l)):
		c.append(x[i][1])
	return c
for _ in range(int(input())):
	n = int(input())
	red = li()
	m = int(input())
	blue = li()
	dp = [0]
	ans = 0
	for x in red:
		ans += x
		dp.append(ans)
	pp = [0]
	ans = 0
	for x in blue:
		ans += x
		pp.append(ans)
	print(max(dp) + max(pp))


def maxSubArraySum(a, size):
	max_so_far = 0
	curr_max = 0
	for i in range(size):
		curr_max += a[i]
		max_so_far = max(curr_max, max_so_far)
	return max_so_far
t = int(input())
for _ in range(t):
	fans = 0
	ans = 0
	for _ in range(2):
		n = int(input())
		l = [int(x) for x in input().split()]
		ans += max(maxSubArraySum(l, n), 0)
	fans += ans
	print(fans)


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))

	def maxarr(arr):
		sum = 0
		msum = 0
		for i in range(len(arr)):
			sum += arr[i]
			if sum > msum:
				msum = sum
		return msum
	print(maxarr(r) + maxarr(b))


t = int(input())
for kk in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	max_r = 0
	sr = 0
	for i in r:
		sr += i
		max_r = max(max_r, sr)
	max_b = 0
	sb = 0
	for i in b:
		sb += i
		max_b = max(max_b, sb)
	print(max(0, r[0], b[0], max_r, max_b, max_r + max_b))


def maxsubsum(n, l):
	maxsum = l[0]
	t = l[0]
	for i in range(1, n):
		t = t + l[i]
		if maxsum < t:
			maxsum = t
	if maxsum < 0:
		maxsum = 0
	return maxsum
t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(int, input().rstrip().split()))
	m = int(input())
	b = list(map(int, input().rstrip().split()))
	m1 = maxsubsum(n, r)
	m2 = maxsubsum(m, b)
	print(m1 + m2)


import sys, threading, heapq
from collections import defaultdict
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def main():
	for _ in range(inp()):
		nr = inp()
		red = inlt()
		nb = inp()
		blue = inlt()
		maxSubA = 0
		prev = 0
		for num in red:
			prev += num
			maxSubA = max(maxSubA, prev)
		prev = 0
		maxSubB = 0
		for num in blue:
			prev += num
			maxSubB = max(maxSubB, prev)
		print(maxSubA + maxSubB)
main()


import math
import collections

def solve(n, r, m, b):
	maxR = maxB = 0
	for i in range(n):
		maxR = max(maxR, sum(r[:i + 1]))
	for i in range(m):
		maxB = max(maxB, sum(b[:i + 1]))
	return maxR + maxB
t = int(input())
for t in range(t):
	n = int(input())
	r = [int(s) for s in input().split()]
	m = int(input())
	b = [int(s) for s in input().split()]
	result = solve(n, r, m, b)
	print(result)


t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	sm_mx = 0
	num_list = []
	sm = 0
	for j in range(n):
		sm += r[j]
		num_list.append(sm)
	if max(num_list) > 0:
		sm_mx += max(num_list)
	num_list = []
	sm = 0
	for j in range(m):
		sm += b[j]
		num_list.append(sm)
	if max(num_list) > 0:
		sm_mx += max(num_list)
	print(sm_mx)


import sys
sys.setrecursionlimit(1000000)
from collections import defaultdict, deque, Counter
from itertools import permutations
from math import sqrt, gcd, pi, factorial
from functools import reduce
from sys import stdin
from bisect import bisect_right, bisect_left
from copy import copy

def calc(x):
	n = len(x)
	ret = [0 for _ in range(n + 1)]
	for i in range(n):
		ret[i + 1] = x[i] + ret[i]
	return max(ret)

def solve(n, r, m, b):
	return calc(r) + calc(b)
t = int(input())
anss = [0 for _ in range(t)]
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	anss[i] = solve(n, r, m, b)
for ans in anss:
	print(ans)


def AddFunction(li):
	ans = [0]
	n = len(li)
	a = 0
	for i in range(n):
		a += li[i]
		ans.append(a)
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	i = 0
	j = 0
	ans1 = AddFunction(r)
	ans2 = AddFunction(b)
	print(max(ans1) + max(ans2))


for _ in range(int(input())):
	ans = 0
	n1 = int(input())
	R = list(map(int, input().split()))
	n2 = int(input())
	B = list(map(int, input().split()))
	for i in range(1, n1):
		R[i] += R[i - 1]
	for i in range(1, n2):
		B[i] += B[i - 1]
	mr = max(R)
	mb = max(B)
	ans = mr + mb
	if mr < 0:
		mr = 0
	if mb < 0:
		mb = 0
	ans = mr + mb
	print(ans)


def leftmss(x):
	summ = 0
	maxsum = 0
	for i in x:
		summ += i
		maxsum = summ if summ > maxsum else maxsum
	return maxsum
t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	r = list(map(int, input().split(' ')))
	m = int(input())
	b = list(map(int, input().split(' ')))
	rsum = leftmss(r)
	bsum = leftmss(b)
	rbsum = rsum + bsum
	ans.append(max(rsum, bsum, rbsum))
for i in range(t):
	print(ans[i])


def solve(a):
	maxv = 0
	c = 0
	for i in a:
		c = c + i
		if c > maxv:
			maxv = c
	return maxv
t = int(input().strip())
for _ in range(t):
	rn = int(input().strip())
	r = list(map(int, input().strip().split()))
	bn = int(input().strip())
	b = list(map(int, input().strip().split()))
	print(solve(r) + solve(b))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	R = list(map(int, sys.stdin.readline().split()))
	m = int(sys.stdin.readline())
	B = list(map(int, sys.stdin.readline().split()))

	def max_prefix(A):
		cur_max = 0
		cur_total = 0
		for a in A:
			cur_total += a
			if cur_total > cur_max:
				cur_max = cur_total
		return cur_max
	max_r = max_prefix(R)
	max_b = max_prefix(B)
	print(max_r + max_b)


def max(l, len):
	max = 0
	total = 0
	for i in range(len):
		total += l[i]
		if total > max:
			max = total
	return max
for i in range(int(input())):
	size_red = int(input())
	red = list(map(lambda x: int(x), input().split(' ')))
	size_blue = int(input())
	blue = list(map(lambda x: int(x), input().split(' ')))
	print(max(red, size_red) + max(blue, size_blue))


t = int(input())
for s in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	if max(r) <= 0 and max(b) <= 0:
		print(0)
	else:
		s = 0
		temp_r = []
		temp_b = []
		for i in range(n):
			s = s + r[i]
			temp_r.append(s)
		s = 0
		for i in range(m):
			s = s + b[i]
			temp_b.append(s)
		if max(temp_r) >= 0 and max(temp_b) >= 0:
			maxi = max(temp_r) + max(temp_b)
		elif max(temp_r) < 0 and max(temp_b) >= 0:
			maxi = max(temp_b)
		elif max(temp_b) < 0 and max(temp_r) >= 0:
			maxi = max(temp_r)
		elif max(temp_b) < 0 and max(temp_r) < 0:
			maxi = 0
		print(maxi)


for _ in range(int(input())):
	nn = input()
	l1 = [int(i) for i in input().split()]
	cc = input()
	l2 = [int(k) for k in input().split()]
	max1 = max2 = 0
	s1 = s2 = 0
	for i in range(len(l1)):
		s1 += l1[i]
		max1 = max(max1, s1)
	for j in range(len(l2)):
		s2 += l2[j]
		max2 = max(max2, s2)
	print(max1 + max2)


def solve(r, b):
	r = [0] + r
	b = [0] + b
	for i in range(1, len(r)):
		r[i] = r[i - 1] + r[i]
	for i in range(1, len(b)):
		b[i] = b[i - 1] + b[i]
	answer = max(r) + max(b)
	return 0 if answer <= 0 else answer

def main():
	test_cases = int(input())
	for _ in range(test_cases):
		input()
		r = list(map(int, input().split()))
		input()
		b = list(map(int, input().split()))
		print(solve(r, b), end='\n')
main()


for _ in range(int(input())):
	n = int(input())
	l1 = [int(__) for __ in input().split()]
	m = int(input())
	l2 = [int(__) for __ in input().split()]
	for i in range(1, n):
		l1[i] = l1[i - 1] + l1[i]
	for i in range(1, m):
		l2[i] = l2[i - 1] + l2[i]
	shit1 = max(l1)
	shit2 = max(l2)
	print(max(0, shit1, shit2, shit1 + shit2))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	m = int(input())
	barr = list(map(int, input().split()))
	(mx1, mx2, s1, s2) = (0, 0, 0, 0)
	for i in range(n):
		s1 += arr[i]
		mx1 = max(mx1, s1)
	for i in range(m):
		s2 += barr[i]
		mx2 = max(mx2, s2)
	print(mx1 + mx2)


def solve():
	n = int(input())
	arr = input().split()
	a = []
	for el in arr:
		a.append(int(el))
	m = int(input())
	arr = input().split()
	b = []
	for el in arr:
		b.append(int(el))
	max_a = -1
	max_sa = 0
	cur_s = 0
	for i in range(n):
		cur_s += a[i]
		if cur_s > max_sa:
			max_a = i
			max_sa = cur_s
	max_b = -1
	max_sb = 0
	cur_s = 0
	for i in range(m):
		cur_s += b[i]
		if cur_s > max_sb:
			max_b = i
			max_sb = cur_s
	return max_sa + max_sb
t = int(input())
while t:
	t -= 1
	print(solve())


t = int(input())
for x in range(t):
	n = int(input())
	ln = list(map(int, input().split()))
	for y in range(1, n):
		ln[y] += ln[y - 1]
	m = int(input())
	lm = list(map(int, input().split()))
	for y in range(1, m):
		lm[y] += lm[y - 1]
	print(max([0, max(lm) + max(ln), max(lm), max(ln)]))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	mpa = -float('inf')
	s = 0
	for x in a:
		s += x
		mpa = max(mpa, s)
	mpb = -float('inf')
	s = 0
	for x in b:
		s += x
		mpb = max(mpb, s)
	print(max(0, max(mpa, 0) + max(mpb, 0)))


import sys
t = int(sys.stdin.readline())
ans_arr = []
for i in range(t):
	n = int(sys.stdin.readline())
	r = [int(x) for x in sys.stdin.readline().split()]
	m = int(sys.stdin.readline())
	b = [int(y) for y in sys.stdin.readline().split()]
	max_one = 0
	t_one = 0
	for g in range(n):
		t_one += r[g]
		max_one = max(max_one, t_one)
	max_two = 0
	t_two = 0
	for h in range(m):
		t_two += b[h]
		max_two = max(max_two, t_two)
	ans_arr.append(str(max_one + max_two))
print('\n'.join(ans_arr))


t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	nums = []
	nums1 = []
	a = 0
	e = 0
	for k in range(len(r)):
		a += r[k]
		nums.append(a)
	for d in range(len(b)):
		e += b[d]
		nums1.append(e)
	w = max(0, max(nums)) + max(0, max(nums1))
	print(w)


from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil

def st():
	return list(stdin.readline().strip())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def inp():
	return int(stdin.readline())

def pr(n):
	return stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	n = inp()
	l = li()
	m = inp()
	k = li()
	x = max(0, l[0])
	y = max(0, k[0])
	for i in range(1, n):
		l[i] += l[i - 1]
		x = max(x, l[i])
	for i in range(1, m):
		k[i] += k[i - 1]
		y = max(y, k[i])
	pr(x + y)
for _ in range(inp()):
	solve()


def problem_sol(n, r, m, b):
	(cum_r, cum_b) = cum_sum(n, r, m, b)
	max_r = max(max(cum_r), 0)
	max_b = max(max(cum_b), 0)
	return max_r + max_b

def cum_sum(n, r, m, b):
	cum_r = [sum(r[:i + 1]) for i in range(n)]
	cum_b = [sum(b[:i + 1]) for i in range(m)]
	return (cum_r, cum_b)
no_inp = int(input())
while no_inp > 0:
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	print(problem_sol(n, r, m, b))
	no_inp -= 1


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
from itertools import permutations, combinations

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
sys.setrecursionlimit(100000)
INF = float('inf')
mod = 10 ** 9 + 7
for t in range(int(data())):
	n = int(data())
	r = mdata()
	m = int(data())
	b = mdata()
	m11 = m22 = 0
	s = s1 = 0
	for i in r:
		s1 += i
		m11 = max(s1, m11)
	s = s1 = 0
	for i in b:
		s1 += i
		m22 = max(s1, m22)
	out(m11 + m22)


res = []
for i in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	l = list(map(int, input().split()))
	u = 0
	for j in range(n):
		r[j] += u
		u = r[j]
	u = 0
	for j in range(m):
		l[j] += u
		u = l[j]
	res.append(max(l + [0]) + max(r + [0]))
print(*res, sep='\n')


n = int(input())
for i in range(n):
	rn = int(input())
	r = [int(r_number) for r_number in input().strip().split()[:rn]]
	bn = int(input())
	b = [int(b_number) for b_number in input().strip().split()[:bn]]
	rmax = 0
	rsum = 0
	bmax = 0
	bsum = 0
	for x in range(rn):
		rsum += r[x]
		rmax = max(rmax, rsum)
	for k in range(bn):
		bsum += b[k]
		bmax = max(bmax, bsum)
	print(rmax + bmax)


def answer(n, r, m, b):
	rsum = 0
	max_rsum = 0
	for i in range(len(r)):
		rsum += r[i]
		if rsum > max_rsum:
			max_rsum = rsum
	bsum = 0
	max_bsum = 0
	for i in range(len(b)):
		bsum += b[i]
		if bsum > max_bsum:
			max_bsum = bsum
	return max_rsum + max_bsum

def main():
	t = int(input())
	n = [0] * t
	r = [0] * t
	m = [0] * t
	b = [0] * t
	for j in range(t):
		n[j] = int(input())
		r[j] = [int(i) for i in input().split()]
		m[j] = int(input())
		b[j] = [int(i) for i in input().split()]
	for j in range(t):
		print(answer(n[j], r[j], m[j], b[j]))
main()


def max_value(list_1, list_2):
	max_1 = 0
	sum_1 = 0
	max_2 = 0
	sum_2 = 0
	for item_1 in list_1:
		sum_1 = sum_1 + item_1
		if max_1 < sum_1:
			max_1 = sum_1
	for item_2 in list_2:
		sum_2 = sum_2 + item_2
		if max_2 < sum_2:
			max_2 = sum_2
	return max_1 + max_2
for i in range(0, int(input())):
	input()
	list_1 = [int(x) for x in input().split()]
	input()
	list_2 = [int(x) for x in input().split()]
	print(max_value(list_1, list_2))


import os
import sys
from io import BytesIO, IOBase
import heapq as h
import bisect
import math as mt
from types import GeneratorType
BUFSIZE = 8192

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
import sys
from math import ceil, log2
INT_MAX = sys.maxsize
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def minVal(x, y):
	return x if x < y else y

def getMid(s, e):
	return s + (e - s) // 2

def RMQUtil(st, ss, se, qs, qe, index):
	if qs <= ss and qe >= se:
		return st[index]
	if se < qs or ss > qe:
		return INT_MAX
	mid = getMid(ss, se)
	return minVal(RMQUtil(st, ss, mid, qs, qe, 2 * index + 1), RMQUtil(st, mid + 1, se, qs, qe, 2 * index + 2))

def RMQ(st, n, qs, qe):
	if qs < 0 or qe > n - 1 or qs > qe:
		print('Invalid Input')
		return -1
	return RMQUtil(st, 0, n - 1, qs, qe, 0)

def constructSTUtil(arr, ss, se, st, si):
	if ss == se:
		st[si] = arr[ss]
		return arr[ss]
	mid = getMid(ss, se)
	st[si] = minVal(constructSTUtil(arr, ss, mid, st, si * 2 + 1), constructSTUtil(arr, mid + 1, se, st, si * 2 + 2))
	return st[si]

def constructST(arr, n):
	x = int(ceil(log2(n)))
	max_size = 2 * int(2 ** x) - 1
	st = [0] * max_size
	constructSTUtil(arr, 0, n - 1, st, 0)
	return st
MOD = 10 ** 9 + 7
mod = 10 ** 9 + 7
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def z_array(s1):
	n = len(s1)
	z = [0] * n
	(l, r, k) = (0, 0, 0)
	for i in range(1, n):
		if i > r:
			(l, r) = (i, i)
			while r < n and s1[r - l] == s1[r]:
				r += 1
			z[i] = r - l
			r -= 1
		else:
			k = i - l
			if z[k] < r - i + 1:
				z[i] = z[k]
			else:
				l = i
				while r < n and s1[r - l] == s1[r]:
					r += 1
				z[i] = r - l
				r -= 1
	return z

def fs(x):
	if x < 2:
		return 0
	return x * (x - 1) // 2
t = int(input())

def solve():
	dp = [[0 for j in range(m + 1)] for i in range(n + 1)]
	maxi = 0
	suma = 0
	for i in range(1, n + 1):
		suma += l1[i - 1]
		dp[i][0] = suma
		for j in range(m + 1):
			if j > 0:
				dp[i][j] = dp[i][j - 1] + l2[j - 1]
			maxi = max(maxi, dp[i][j])
	curr = 0
	for i in range(m):
		curr += l2[i]
		maxi = max(maxi, curr)
	return maxi
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	m = int(input())
	l2 = list(map(int, input().split()))
	print(solve())


from math import *

def panda(n, m, l1, l2):
	(la, lb) = ([], [])
	(s1, s2) = (0, 0)
	for i in range(n):
		s1 += l1[i]
		la.append(s1)
	for i in range(m):
		s2 += l2[i]
		lb.append(s2)
	return max(max(la), 0) + max(max(lb), 0)
t = int(input())
for _ in range(t):
	n = int(input())
	l1 = list(map(int, input().split()))
	m = int(input())
	l2 = list(map(int, input().split()))
	print(panda(n, m, l1, l2))


for i in range(0, int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(1, n):
		l[i] += l[i - 1]
	m = int(input())
	p = list(map(int, input().split()))
	for i in range(1, m):
		p[i] += p[i - 1]
	print(max(max(l) + max(p), max(l), max(p), 0))


tc = int(input())
for _ in range(tc):
	x = int(input())
	listred = list(map(int, input().split()))
	maxred = []
	countred = 0
	y = int(input())
	listblue = list(map(int, input().split()))
	maxblue = []
	countblue = 0
	for i in listred:
		maxred += [countred]
		countred += i
	maxred += [countred]
	for i in listblue:
		maxblue += [countblue]
		countblue += i
	maxblue += [countblue]
	print(max(maxred) + max(maxblue))


import math
t = int(input())
while t > 0:
	n = int(input())
	inp = input()
	red = list(map(int, inp.split(' ')))
	m = int(input())
	inp = input()
	blue = list(map(int, inp.split(' ')))
	sum1 = 0
	max1 = 0
	for i in range(0, n):
		sum1 += red[i]
		if sum1 > max1:
			max1 = sum1
	sum2 = 0
	max2 = 0
	for i in range(0, m):
		sum2 += blue[i]
		if sum2 > max2:
			max2 = sum2
	print(max1 + max2)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	aa = 0
	bb = 0
	c = 0
	for i in range(n):
		a[i] += c
		c = a[i]
	c = 0
	for j in range(m):
		b[j] += c
		c = b[j]
	aa = max(0, max(a))
	bb = max(0, max(b))
	print(aa + bb)


n = int(input())
for i in range(n):
	max1 = max2 = cur = 0
	sz1 = int(input())
	lst = input().split()
	for j in range(sz1):
		cur += int(lst[j])
		max1 = max(max1, cur)
	sz2 = int(input())
	cur = 0
	lst = input().split()
	for j in range(sz2):
		cur += int(lst[j])
		max2 = max(max2, cur)
	print(max1 + max2)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	n2 = int(input())
	l2 = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	curr = 0
	for i in range(n):
		curr += l[i]
		c1 = max(c1, curr)
	curr = 0
	for i in range(n2):
		curr += l2[i]
		c2 = max(c2, curr)
	print(c1 + c2)


maxint = 9223372036854775807

def maxSubArraySum(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
	return max_so_far
for i in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	print(maxSubArraySum(r, n) + maxSubArraySum(b, m))


from itertools import accumulate
t = int(input())
for i in range(t):
	n = int(input())
	l1 = [int(i) for i in input().split()]
	m = int(input())
	l2 = [int(i) for i in input().split()]
	l1 = accumulate(l1)
	l2 = accumulate(l2)
	print(max(0, max(l1)) + max(0, max(l2)))


def main():
	for _ in range(int(input())):
		dp = [0, 0]
		for i in range(2):
			res = 0
			input()
			for j in map(int, input().split()):
				res += j
				dp[i] = max(dp[i], res)
		print(sum(dp))
main()


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def output(*args):
	sys.stdout.buffer.write(('\n'.join(map(str, args)) + '\n').encode('utf-8'))

def main():
	from itertools import accumulate
	t = int(input())
	ans_a = [''] * t
	for ti in range(t):
		n = int(input())
		red = list(accumulate([0] + list(map(int, input().split()))))
		m = int(input())
		blue = list(accumulate([0] + list(map(int, input().split()))))
		ans = max(red) + max(blue)
		ans_a[ti] = str(ans)
	output(*ans_a)
main()


import sys
import io, os
input = sys.stdin.buffer.readline
from itertools import accumulate
t = int(input())
for _ in range(t):
	n = int(input())
	R = list(map(int, input().split()))
	m = int(input())
	B = list(map(int, input().split()))
	CR = list(accumulate([0] + R))
	CB = list(accumulate([0] + B))
	print(max(0, max(CR) + max(CB)))


def make_p(n, a):
	p = [0]
	for i in range(n):
		p.append(p[-1] + a[i])
	return p

def solve(n, r, m, b):
	pr = make_p(n, r)
	pb = make_p(m, b)
	return max(pr) + max(pb)

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		r = list(map(int, input().split()))
		m = int(input())
		b = list(map(int, input().split()))
		print(solve(n, r, m, b))
main()


def maxsum(r, b):
	maxr = 0
	s1 = 0
	for i in range(len(r)):
		s1 = s1 + r[i]
		if s1 > maxr:
			maxr = s1
	s2 = 0
	maxb = 0
	for j in range(len(b)):
		s2 = s2 + b[j]
		if s2 > maxb:
			maxb = s2
	return maxr + maxb
x = int(input())
m = []
for i in range(x):
	a = input()
	b = input()
	c = input()
	d = input()
	b1 = b.split(' ')
	b2 = [int(t) for t in b1]
	d1 = d.split(' ')
	d2 = [int(t) for t in d1]
	m.append((b2, d2))
for j in range(x):
	print(maxsum(m[j][0], m[j][1]))


t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	r_max = 0
	r_curr = 0
	for q in range(n):
		r_curr += r[q]
		if r_curr > r_max:
			r_max = r_curr
	b_max = 0
	b_curr = 0
	for q in range(m):
		b_curr += b[q]
		if b_curr > b_max:
			b_max = b_curr
	print(b_max + r_max)


for __ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	for i in range(1, n):
		r[i] = r[i] + r[i - 1]
	for i in range(1, m):
		b[i] = b[i] + b[i - 1]
	a = 0
	b1 = 0
	for i in range(n):
		a = max(a, r[i])
	for i in range(m):
		b1 = max(b1, b[i])
	print(a + b1)


def solve(a, n):
	(s, l) = (0, [])
	for i in range(n):
		l.append(s)
		s += a[i]
	l.append(s)
	return max(l)
for pratyush in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	print(solve(a, n) + solve(b, m))


answer = ''
t = int(input())
for _ in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	for _ in range(1, n):
		r[_] += r[_ - 1]
	for _ in range(1, m):
		b[_] += b[_ - 1]
	max_total = max(0, max(r), max(b), max(r) + max(b))
	answer += '%d\n' % max_total
print(answer.strip())


t = int(input())

def dp(arr):
	prev = 0
	for i in range(len(arr) - 1, -1, -1):
		prev = max(0, prev + arr[i])
	return prev
for k in range(t):
	r = int(input())
	red = list(map(int, input().split(' ')))
	b = int(input())
	blue = list(map(int, input().split(' ')))
	print(dp(red) + dp(blue))


from typing import List

def check_max(some_list: List[int]) -> int:
	s_max = 0
	cum_sum = 0
	for s in some_list:
		cum_sum += s
		if s_max < cum_sum:
			s_max = cum_sum
	return s_max
t = int(input())
for _ in range(t):
	n = int(input())
	r = [int(item) for item in input().split(' ')]
	m = int(input())
	b = [int(item) for item in input().split(' ')]
	print(check_max(r) + check_max(b))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def maa():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	a = lis()
	m = inp()
	b = lis()
	p1 = [0]
	p2 = [0]
	for i in a:
		p1.append(p1[-1] + i)
	for i in b:
		p2.append(p2[-1] + i)
	print(max(p1) + max(p2))


for _ in range(int(input())):
	n = int(input())
	red = list(map(int, input().split()))
	m = int(input())
	blue = list(map(int, input().split()))
	prefix1 = []
	prefix2 = []
	ans = 0
	for i in range(n):
		ans += red[i]
		prefix1.append(ans)
	ans = 0
	for i in range(m):
		ans += blue[i]
		prefix2.append(ans)
	print(max(max(prefix1), 0) + max(max(prefix2), 0))


def take(a):
	l = list(map(int, input().split()))
	v = 0
	n = l[0]
	if n > v:
		v = n
	for t in range(a - 1):
		n += l[t + 1]
		if n > v:
			v = n
	return v
for _ in range(int(input())):
	l1 = []
	l2 = []
	a = int(input())
	v = take(a)
	b = int(input())
	vv = take(b)
	print(v + vv)


sol = []
for test in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	res = 0
	sa = 0
	sb = 0
	ra = 0
	rb = 0
	for i in a:
		sa += i
		ra = max(ra, sa)
	for i in b:
		sb += i
		rb = max(rb, sb)
	sol.append(ra + rb)
for r in sol:
	print(r)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = int(input())
	s = list(map(int, input().split()))
	l1 = [0]
	ls = 0
	s1 = [0]
	ss = 0
	for i in range(n):
		ls = ls + l[i]
		l1.append(ls)
	for i in range(m):
		ss = ss + s[i]
		s1.append(ss)
	print(max(l1) + max(s1))


def massivy(n, r):
	sum = 0
	msum = 0
	for j in range(n):
		sum += r[j]
		if sum > msum:
			msum = sum
	return msum
t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	mr = massivy(n, r)
	mb = massivy(m, b)
	if mr + mb < 0:
		print(0)
	else:
		print(mr + mb)


def kadane(l):
	m = max(l)
	if m <= 0:
		return 0
	maxi = 0
	add = 0
	for i in l:
		add += i
		if add > maxi:
			maxi = add
	return maxi
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = int(input())
	l1 = list(map(int, input().split()))
	n1 = kadane(l)
	n2 = kadane(l1)
	print(n1 + n2)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	k = int(input())
	l1 = list(map(int, input().split()))
	p = [l[0]]
	for x in l[1:]:
		p.append(p[-1] + x)
	p1 = [l1[0]]
	for x in l1[1:]:
		p1.append(p1[-1] + x)
	m1 = max(max(p), 0)
	m2 = max(max(p1), 0)
	print(m1 + m2)


def cnt(i, s):
	sm = 0
	smd = 0
	for j in range(i):
		smd += s[j]
		if smd > 0:
			sm += smd
			smd = 0
	return sm
t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	print(cnt(n, r) + cnt(m, b))


from itertools import *
f = lambda : max(0, *accumulate(map(int, input().split())))
exec(f() * 'f();r=f();f();print(r+f());')


import sys
input = sys.stdin.readline
from sys import stdin, stdout
from collections import defaultdict, Counter
M = 10 ** 9 + 7

def main():
	for _ in range(int(input())):
		n = int(input())
		r = [int(s) for s in input().split()]
		m = int(input())
		b = [int(s) for s in input().split()]
		pre1 = [r[0]] * n
		pre2 = [b[0]] * m
		ans = max(0, max(r[0], b[0]))
		for i in range(1, n):
			pre1[i] = pre1[i - 1] + r[i]
			ans = max(ans, pre1[i])
		for i in range(1, m):
			pre2[i] = pre2[i - 1] + b[i]
			ans = max(ans, pre2[i])
		for i in range(n):
			for j in range(m):
				ans = max(ans, pre1[i] + pre2[j])
		print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	ass = list(map(int, input().split()))
	m = int(input())
	baa = list(map(int, input().split()))
	dp1 = [0] * n
	dp2 = [0] * m
	(res1, res2) = (0, 0)
	for _ in range(n):
		res1 += ass[_]
		if res1 <= 0:
			dp1[_] = 0
		else:
			dp1[_] = res1
	for _ in range(m):
		res2 += baa[_]
		if res2 <= 0:
			dp2[_] = 0
		else:
			dp2[_] = res2
	print(max(dp1) + max(dp2))


size = int(input())
for i in range(size):
	size1 = int(input())
	l1 = list(map(int, input().split()))
	size2 = int(input())
	l2 = list(map(int, input().split()))
	t1 = [l1[0]]
	for i in range(size1 - 1):
		t1.append(t1[i] + l1[i + 1])
	t2 = [l2[0]]
	for i in range(size2 - 1):
		t2.append(t2[i] + l2[i + 1])
	print(max(0, max(t1) + max(t2), max(t1), max(t2)))


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	r = list(map(int, stdin.readline().split()))
	m = int(stdin.readline())
	b = list(map(int, stdin.readline().split()))
	(mr, mb) = (r[0], b[0])
	(cr, cb) = (r[0], b[0])
	for i in r[1:]:
		cr += i
		if cr > mr:
			mr = cr
	for i in b[1:]:
		cb += i
		if cb > mb:
			mb = cb
	print(max(0, mr + mb, mr, mb))


from sys import stdin
from sys import stdout
from math import *
import sys
for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	a1 = [0]
	m1 = 0
	a2 = [0]
	m2 = 0
	for i in range(n):
		a1.append(a1[-1] + a[i])
		m1 = max(m1, a1[-1])
	for i in range(m):
		a2.append(a2[-1] + b[i])
		m2 = max(m2, a2[-1])
	print(m1 + m2)


def maxsum(l):
	m = 0
	c = 0
	for i in l:
		c += i
		m = max(c, m)
	return m
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	print(maxsum(a) + maxsum(b))


for _ in range(int(input())):
	n = int(input())
	r = [int(j) for j in input().split()]
	m = int(input())
	b = [int(k) for k in input().split()]
	(t, s) = (0, 0)
	(e, f) = ([], [])
	for i in r:
		t = t + i
		e.append(t)
	for u in b:
		s = s + u
		f.append(s)
	if max(e) * max(f) < 0:
		print(max(max(e), max(f)))
	elif max(e) >= 0 and max(f) >= 0:
		print(max(e) + max(f))
	else:
		print(0)


for i in range(int(input())):
	n = int(input())
	r = [int(i) for i in input().split()]
	m = int(input())
	b = [int(i) for i in input().split()]
	m1 = 0
	s = 0
	for i in range(n):
		s += r[i]
		m1 = max(m1, s)
	s2 = 0
	m2 = 0
	for i in range(m):
		s2 += b[i]
		m2 = max(m2, s2)
	print(m1 + m2)


def probB(n, r, m, b):
	prefix1 = []
	prefix2 = []
	sum = 0
	for i in r:
		sum += i
		prefix1.append(sum)
	sum = 0
	for j in b:
		sum += j
		prefix2.append(sum)
	return max(max(prefix1) + max(prefix2), max(prefix2), max(prefix1), 0)
t = int(input())
for y in range(t):
	n = int(input())
	A = [int(i) for i in input().split()][:n]
	m = int(input())
	B = [int(i) for i in input().split()][:m]
	print(probB(n, A, m, B))


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	c = 0
	arr1 = []
	for x in r:
		c += x
		arr1.append(c)
	c = 0
	arr2 = []
	for x in b:
		c += x
		arr2.append(c)
	print(max(arr1 + [0]) + max(arr2 + [0]))


for _ in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	if n > m:
		t = a
		a = b
		b = t
	a += [0] * abs(m - n)
	tot = 0
	atot = 0
	btot = 0
	for (x, y) in zip(a, b):
		atot += x
		btot += y
		if atot > 0:
			tot += atot
			atot = 0
		if btot > 0:
			tot += btot
			btot = 0
	print(tot)


import sys
import math

def solve(arr, n):
	s = 0
	acc = 0
	for x in arr:
		acc += x
		if acc > 0:
			s += acc
			acc = 0
	return s
lines = [list(map(int, line.split())) for line in sys.stdin.readlines()]
lines.pop(0)
i = 1
while lines:
	n = lines[0][0]
	r = lines[1]
	m = lines[2][0]
	b = lines[3]
	while r and r[-1] < 0:
		r.pop(-1)
	while b and b[-1] < 0:
		b.pop(-1)
	R = solve(r, n) if r else 0
	B = solve(b, m) if b else 0
	print(R + B)
	i += 1
	lines = lines[4:]


res = ''
for _ in range(int(input())):
	n = int(input())
	reds = tuple(map(int, input().split()))
	m = int(input())
	blues = tuple(map(int, input().split()))
	red_presum = [0]
	blue_presum = [0]
	for i in reds:
		red_presum.append(red_presum[-1] + i)
	for i in blues:
		blue_presum.append(blue_presum[-1] + i)
	res += str(max(red_presum) + max(blue_presum)) + '\n'
print(res)


from itertools import accumulate
s = lambda x: max(0, max(accumulate(x)))
for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	print(s(r) + s(b))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	m = int(input())
	b = list(map(int, input().strip().split()))
	pa = [a[0]]
	pb = [b[0]]
	mxa = pa[0]
	mxb = pb[0]
	for i in range(1, n):
		c = a[i] + pa[-1]
		pa.append(c)
		if mxa < c:
			mxa = c
	for i in range(1, m):
		d = b[i] + pb[-1]
		pb.append(d)
		if mxb < d:
			mxb = d
	if mxa >= 0 and mxb >= 0:
		print(mxa + mxb)
	elif mxa < 0 and mxb >= 0:
		print(mxb)
	elif mxa >= 0 and mxb < 0:
		print(mxa)
	else:
		print(0)


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	c1 = [0] + list(accumulate(a))
	c2 = [0] + list(accumulate(b))
	print(max(0, max(c1) + max(c2)))


t = int(input())

def find_max(numbers):
	max_count = 0
	count = 0
	for number in numbers:
		count += number
		max_count = max(max_count, count)
	return max_count
for tests in range(t):
	n = int(input())
	redlist = list(map(int, input().split()))
	m = int(input())
	bluelist = list(map(int, input().split()))
	print(find_max(redlist) + find_max(bluelist))


t = int(input())
while t:
	n = int(input())
	a = [int(x) for x in input().split()]
	m = int(input())
	b = [int(x) for x in input().split()]
	amax = 0
	aval = 0
	for i in a:
		aval += i
		amax = max(amax, aval)
	bmax = 0
	bval = 0
	for i in b:
		bval += i
		bmax = max(bmax, bval)
	print(amax + bmax)
	t -= 1


from copy import copy

def m(a):
	n = len(a)
	(s, m) = (0, 0)
	for i in range(n):
		m += a[i]
		s = max(s, m)
	return s

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		m1 = int(input())
		b = list(map(int, input().split()))
		print(max(0, m(a) + m(b)))
main()


def fun(arr):
	mx = 0
	cs = 0
	for x in arr:
		cs += x
		if cs > mx:
			mx = cs
	return mx
t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	ans = fun(arr)
	n = int(input())
	arr = list(map(int, input().split()))
	ans += fun(arr)
	print(ans)
	t -= 1


from itertools import accumulate
for _ in range(int(input())):
	n = int(input())
	A = list(accumulate(map(int, input().split()), initial=0))
	m = int(input())
	B = list(accumulate(map(int, input().split()), initial=0))
	print(max(0, max(A) + max(0, max(B))))


for _ in range(int(input())):
	n = int(input())
	red = list(map(int, input().split()))
	m = int(input())
	blue = list(map(int, input().split()))
	temp1 = 0
	s = 0
	for i in red:
		s += i
		if s > temp1:
			temp1 = s
	temp2 = 0
	s = 0
	for i in blue:
		s += i
		if s > temp2:
			temp2 = s
	print(max(0, temp1 + temp2))


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	(maxr, maxb) = (0, 0)
	s = 0
	for item in r:
		s += item
		maxr = max(maxr, s)
	s = 0
	for item in b:
		s += item
		maxb = max(maxb, s)
	print(maxr + maxb)


for j in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	m = int(input())
	b = [int(j) for j in input().split()]
	s = 0
	t = 0
	S = []
	T = []
	for i in a:
		s += i
		S.append(s)
	for i in b:
		t += i
		T.append(t)
	if max(S) * max(T) < 0:
		print(max(max(S), max(T)))
	elif max(S) >= 0 and max(T) >= 0:
		print(max(S) + max(T))
	else:
		print(0)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	m = int(input())
	B = list(map(int, input().split()))
	pref_A = [0]
	pref_B = [0]
	for i in A:
		pref_A.append(pref_A[-1] + i)
	for i in B:
		pref_B.append(pref_B[-1] + i)
	print(max(pref_B) + max(pref_A))


case = int(input())
for i in range(case):
	n = int(input())
	nn = list(map(int, input().split()))
	m = int(input())
	mm = list(map(int, input().split()))
	nnmax = 0
	mmmax = 0
	ncurrent = 0
	mcurrent = 0
	for t in range(n):
		ncurrent += nn[t]
		if ncurrent > nnmax:
			nnmax = ncurrent
	for tt in range(m):
		mcurrent += mm[tt]
		if mcurrent > mmmax:
			mmmax = mcurrent
	print(mmmax + nnmax)


t = int(input())
for i in range(0, t):
	n = int(input())
	lis1 = list(map(int, input().split()))
	m = int(input())
	lis2 = list(map(int, input().split()))
	p_max = -1000000
	s = 0
	for j in lis1:
		s = s + j
		if s > p_max:
			p_max = s
		else:
			pass
	p2_max = -1000000
	s = 0
	for j in lis2:
		s = s + j
		if s > p2_max:
			p2_max = s
		else:
			pass
	if p_max <= 0 and p2_max > 0:
		print(p2_max)
	elif p2_max <= 0 and p_max > 0:
		print(p_max)
	elif p_max <= 0 and p2_max <= 0:
		print(0)
	else:
		print(p2_max + p_max)


t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	sum_r = 0
	max_starting_r = 0
	for j in range(n):
		sum_r += r[j]
		max_starting_r = max(max_starting_r, sum_r)
	sum_b = 0
	max_starting_b = 0
	for j in range(m):
		sum_b += b[j]
		max_starting_b = max(max_starting_b, sum_b)
	print(max_starting_r + max_starting_b)


import math
import sys

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	n = Read.int()
	r = Read.list_int()
	m = Read.int()
	b = Read.list_int()
	rs = [0]
	for i in r:
		v = rs[-1] + i
		rs.append(v)
	bs = [0]
	for i in b:
		v = bs[-1] + i
		bs.append(v)
	print(max(rs) + max(bs))
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


n = int(input())

def f(t):
	ans = [0]
	ans.append(t[0])
	for i in range(1, len(t)):
		ans.append(ans[i] + t[i])
	return max(ans)
for i in range(n):
	a = int(input())
	r = list(map(int, input().split()))
	b = int(input())
	l = list(map(int, input().split()))
	print(f(r) + f(l))


import sys
t = int(sys.stdin.readline().strip())
for _ in range(t):
	n = int(sys.stdin.readline().strip())
	a = list(map(int, sys.stdin.readline().split()))
	m = int(sys.stdin.readline().strip())
	b = list(map(int, sys.stdin.readline().split()))
	mx1 = 0
	cnt = 0
	for j in a:
		cnt += j
		mx1 = max(mx1, cnt)
	mx2 = 0
	cnt = 0
	for i in b:
		cnt += i
		mx2 = max(mx2, cnt)
	print(mx1 + mx2)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	R = list(map(int, input().split()))
	m = int(input())
	B = list(map(int, input().split()))
	ma1 = ma2 = 0
	curr = 0
	for i in range(n):
		curr += R[i]
		ma1 = max(ma1, curr)
	curr = 0
	for i in range(m):
		curr += B[i]
		ma2 = max(ma2, curr)
	return max(ma1 + ma2, 0)
for _ in range(int(input())):
	print(solve())


def summax(l):
	n = len(l)
	(sumy, maxy) = (0, 0)
	for i in range(n):
		sumy += l[i]
		if sumy > maxy:
			maxy = sumy
	return maxy
n1 = int(input())
for _ in range(n1):
	n2 = int(input())
	p = input()
	x = [int(num) for num in p.split()]
	n3 = int(input())
	q = input()
	y = [int(num) for num in q.split()]
	print(summax(x) + summax(y))


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	(c, t, prev, prevv) = (0, 0, 0, 0)
	for i in r:
		t += i
		prev = max(t, prev)
	t = 0
	for i in b:
		t += i
		prevv = max(t, prevv)
	if prev < 0:
		prev = 0
	elif prevv < 0:
		prevv = 0
	print(prev + prevv)


t = int(input())
for testCaseCounter in range(t):
	n = int(input())
	reds = [int(amit) for amit in input().split(' ')]
	m = int(input())
	blues = [int(amit) for amit in input().split(' ')]
	rpref = [0] * len(reds)
	rpref[0] = reds[0]
	for i in range(1, len(reds)):
		rpref[i] = rpref[i - 1] + reds[i]
	bpref = [0] * len(blues)
	bpref[0] = blues[0]
	for i in range(1, len(blues)):
		bpref[i] = bpref[i - 1] + blues[i]
	rprefMaxVal = -1
	for i in range(len(rpref)):
		if rpref[i] > 0 and rpref[i] > rprefMaxVal:
			rprefMaxVal = rpref[i]
	rCont = max(0, rprefMaxVal)
	bprefMaxVal = -1
	for i in range(len(bpref)):
		if bpref[i] > 0 and bpref[i] > bprefMaxVal:
			bprefMaxVal = bpref[i]
	bCont = max(0, bprefMaxVal)
	print(rCont + bCont)


import collections
import math
from heapq import *
for t in range(1, int(input()) + 1):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	out = 0
	val = v1 = v2 = 0
	for i in r:
		val += i
		v1 = max(v1, val)
	val = 0
	for i in b:
		val += i
		v2 = max(v2, val)
	print(v1 + v2)


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	mr = 0
	mb = 0
	temp1 = 0
	temp2 = 0
	for i in range(n):
		temp1 += r[i]
		mr = max(temp1, mr)
	for j in range(m):
		temp2 += b[j]
		mb = max(temp2, mb)
	print(mr + mb)


from sys import stdin
input = stdin.readline

def checkMax(l):
	ans = [0]
	m = 0
	for i in l:
		m += i
		ans.append(m)
	return max(ans)

def solve():
	n = int(input())
	ln = list(map(int, input().split()))
	m = int(input())
	lm = list(map(int, input().split()))
	return max(0, checkMax(ln) + checkMax(lm))
for _ in range(int(input())):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	ans_r = 0
	sum_r = 0
	for i in r:
		sum_r += i
		ans_r = max(ans_r, sum_r)
	ans_b = 0
	sum_b = 0
	for i in b:
		sum_b += i
		ans_b = max(ans_b, sum_b)
	print(ans_b + ans_r)


a = int(input())

def llll(lis):
	ls = []
	for h in range(len(lis) + 1):
		ls.append(sum(lis[0:h]))
	ma = max(ls)
	return ma
for i in range(a):
	m = int(input())
	lm = list(map(int, input().split()))
	n = int(input())
	ln = list(map(int, input().split()))
	print(llll(lm) + llll(ln))


t = int(input())
res = []

def maxser(a, n):
	m = 0
	s = a[0]
	if s > m:
		m = s
	for i in range(1, n):
		s += a[i]
		if s > m:
			m = s
	return m
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	res.append(maxser(a, n) + maxser(b, m))
for i in res:
	print(i)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	m = int(input())
	l2 = list(map(int, input().split()))
	a = max1 = b = max2 = 0
	for v in l1:
		a += v
		max1 = max(max1, a)
	for v in l2:
		b += v
		max2 = max(max2, b)
	print(max1 + max2)


import sys
rl = lambda : list(map(int, sys.stdin.readline().split()))
for _ in range(int(input())):
	n = int(input())
	R = rl()
	m = int(input())
	B = rl()
	(maxR, maxB) = (0, 0)
	for i in range(n):
		maxR = max(maxR, sum(R[:i + 1]))
	for j in range(m):
		maxB = max(maxB, sum(B[:j + 1]))
	print(maxR + maxB)


a = int(input())
for i in range(a):
	B = input()
	b = list(map(int, input().split()))
	C = input()
	c = list(map(int, input().split()))
	D = []
	k = 0
	for j in b:
		k += j
		D.append(k)
	s = max(D)
	D = []
	k = 0
	for j in c:
		k += j
		D.append(k)
	p = max(D)
	if p > 0 and s > 0:
		print(s + p)
	elif p > 0:
		print(p)
	elif s > 0:
		print(s)
	else:
		print('0')


def max_sum(l):
	(s, s1) = (l[0], l[0])
	for i in l[1:]:
		s1 += i
		if s < s1:
			s = s1
	return s
for _ in range(int(input())):
	n = int(input())
	l1 = [int(i) for i in input().split()]
	m = int(input())
	l2 = [int(i) for i in input().split()]
	(max1, max2) = (max_sum(l1), max_sum(l2))
	print(max(0, max1, max2, max1 + max2))


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	m = int(input())
	b = [int(x) for x in input().split()]

	def mpref(arr):
		cur = 0
		res = 0
		for x in arr:
			cur += x
			res = max(res, cur)
		return res
	print(mpref(a) + mpref(b))


import sys

class BRedAndBlue:

	def solve(self, tc=0):
		for _ in range(int(input())):
			n = int(input())
			r = [int(_) for _ in input().split()]
			m = int(input())
			b = [int(_) for _ in input().split()]
			ri = bi = 0
			answers = [0]
			prer = [0]
			preb = [0]
			for i in range(len(r)):
				prer.append(prer[-1] + r[i])
			for i in range(len(b)):
				preb.append(preb[-1] + b[i])
			print(max(prer) + max(preb))
solver = BRedAndBlue()
input = sys.stdin.readline
solver.solve()


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, R, M, B):
	prefR = [0]
	for x in R:
		prefR.append(prefR[-1] + x)
	prefB = [0]
	for x in B:
		prefB.append(prefB[-1] + x)
	return max(prefR) + max(prefB)
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N,) = [int(x) for x in input().split()]
	R = [int(x) for x in input().split()]
	(M,) = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	ans = solve(N, R, M, B)
	print(ans)


from collections import Counter
import string
import math
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
testcases = vary(1)
for _ in range(testcases):
	n = vary(1)
	a = array_int()
	m = vary(1)
	b = array_int()
	sumt = 0
	ans = 0
	for i in range(n):
		sumt += a[i]
		ans = max(ans, sumt)
	sumt = 0
	ans1 = 0
	for i in range(m):
		sumt += b[i]
		ans1 = max(ans1, sumt)
	print(max(0, ans + ans1))


from itertools import accumulate
t = int(input())
while t > 0:
	t -= 1
	n = input()
	MPR = max(accumulate(map(int, input().split(' '))))
	m = input()
	MPB = max(accumulate(map(int, input().split(' '))))
	print(max(0, MPR, MPB, MPR + MPB))


import sys
import math
from heapq import heappop, heappush, heapify
intl = lambda : list(map(int, inp().split(' ')))
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
mint = lambda : map(int, inp().split())
finp = lambda : list(map(float, inp().split(' ')))
flush = lambda : sys.stdout.flush()
ran = lambda x: range(len(x))
enum = lambda x, y=0: enumerate(x, y)
mati = lambda n, fun=0: [[fun if type(fun) is int else fun(i, j) for j in range(n)] for i in range(n)]
vec = lambda n, fun=0: [fun if type(fun) is int else fun(i) for i in range(n)]
vecst = lambda n, fun=0: [fun if type(fun) is int else fun() for i in range(n)]
vecadv = lambda n, fun=0, s=0, st=1: [fun if type(fun) is int else fun(i) for i in range(s, n, st)]
matinp = lambda n: [intl() for i in range(n)]
for _ in range(iinp()):
	n = iinp()
	a = intl()
	m = iinp()
	b = intl()
	sx = 0
	ansx = 0
	for i in a:
		sx += i
		ansx = max(ansx, sx)
	sy = 0
	ansy = 0
	for i in b:
		sy += i
		ansy = max(ansy, sy)
	print(ansx + ansy)


from sys import stdin
lst = list(map(int, stdin.read().split()))
s = 0

def inp(n=1):
	global s
	ret = lst[s:s + n]
	s += n
	return ret

def inp1():
	return inp()[0]
t = inp1()
for _ in range(t):
	n = inp1()
	r = inp(n)
	m = inp1()
	b = inp(m)
	sumr = [0]
	sumb = [0]
	for i in range(len(r)):
		sumr.append(sumr[i] + r[i])
	for i in range(len(b)):
		sumb.append(sumb[i] + b[i])
	print(max(sumr) + max(sumb))


def maxSumPrefix(A):
	(Sum, maxSum) = (A[0], A[0])
	for i in range(1, len(A)):
		Sum += A[i]
		if maxSum < Sum:
			maxSum = Sum
	return maxSum
for t in range(int(input())):
	n = int(input())
	N = [int(c) for c in input().split()]
	m = int(input())
	M = [int(c) for c in input().split()]
	(maxN, maxM) = (maxSumPrefix(N), maxSumPrefix(M))
	print(max(0, maxN, maxM, maxN + maxM))


def rb(n, r, m, b):
	(p1, p2) = (0, 0)
	(sum1, sum2) = (0, 0)
	for i in r:
		sum1 += i
		if p1 <= sum1:
			p1 = sum1
	for j in b:
		sum2 += j
		if p2 <= sum2:
			p2 = sum2
	return p1 + p2
t = int(input())
for _ in range(t):
	n = int(input())
	r = [int(i) for i in input().split()]
	m = int(input())
	b = [int(i) for i in input().split()]
	print(rb(n, r, m, b))


def vivod(max):
	if max < 0:
		print(0)
	else:
		print(max)
for i in range(int(input())):
	n = int(input())
	mass_n = list(map(int, input().split()))
	m = int(input())
	mass_m = list(map(int, input().split()))
	max_1 = -100000
	sum = 0
	for i in range(0, n):
		sum += mass_n[i]
		if sum > max_1:
			max_1 = sum
	max_2 = -100000
	sum = 0
	for i in range(0, m):
		sum += mass_m[i]
		if sum > max_2:
			max_2 = sum
	if (max_1 < 0) & (max_2 > max_1):
		vivod(max_2)
	elif (max_2 < 0) & (max_1 > max_2):
		vivod(max_1)
	elif max_1 + max_2 < 0:
		print(0)
	else:
		vivod(max_1 + max_2)


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	r_max = 0
	r_sum = 0
	for i in range(n):
		r_sum += r[i]
		r_max = max(r_max, r_sum)
	b_max = 0
	b_sum = 0
	for i in range(m):
		b_sum += b[i]
		b_max = max(b_max, b_sum)
	print(r_max + b_max)


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = int(input())
	d = list(map(int, input().split()))
	(sum1, sum2) = (0, 0)
	(maxa1, maxa2) = (0, 0)
	for elem in b:
		sum1 += elem
		if sum1 > maxa1:
			maxa1 = sum1
	for elem in d:
		sum2 += elem
		if sum2 > maxa2:
			maxa2 = sum2
	print(max(0, maxa1 + maxa2, maxa1, maxa2))


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	sr = 0
	sr_ = 0
	for i in r:
		sr += i
		sr_ = max(sr_, sr)
	sb = 0
	sb_ = 0
	for i in b:
		sb += i
		sb_ = max(sb_, sb)
	print(sr_ + sb_)


numofcases = int(input())

def findmax(numofe, elist):
	pl = [0]
	index = 0
	total = 0
	while index < numofe:
		total += int(elist[index])
		pl.append(total)
		index += 1
	return max(pl)
ans = []
for x in range(0, numofcases):
	l1e = int(input())
	l1 = input().split(' ')
	l2e = int(input())
	l2 = input().split(' ')
	l1max = findmax(l1e, l1)
	l2max = findmax(l2e, l2)
	ans.append(l1max + l2max)
for i in ans:
	print(i)


t = int(input())

def sumbest(a, l):
	s = 0
	sbest = 0
	for i in range(l):
		s += a[i]
		if s > sbest:
			sbest = s
	return sbest
for _ in range(t):
	n = int(input())
	red = list(map(int, input().split()))
	m = int(input())
	blue = list(map(int, input().split()))
	print(sumbest(red, n) + sumbest(blue, m))


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	for i in range(1, n):
		r[i] = r[i - 1] + r[i]
	for i in range(1, m):
		b[i] = b[i - 1] + b[i]
	print(max(0, max(r)) + max(0, max(b)))


import sys
import math

def alele():
	return list(map(int, sys.stdin.readline().strip().split()))

def ilele():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	input()
	A = alele()
	input()
	B = alele()
	(a, b, c) = (0, 0, 0)
	for i in A:
		c += i
		a = max(a, c)
	c = 0
	for i in B:
		c += i
		b = max(b, c)
	print(a + b)


t = int(input())
for aa in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	(p, q, r, s) = (0, 0, 0, 0)
	for i in a:
		q = q + i
		p = max(p, q)
	for i in b:
		s = s + i
		r = max(r, s)
	print(max(0, p + r))


import re
import sys
exit = sys.exit
from bisect import bisect_left as bsl, bisect_right as bsr
from collections import Counter, defaultdict as ddict, deque
from functools import lru_cache
cache = lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum = enumerate
ri = lambda : int(rln())
ris = lambda : list(map(int, rfs()))
rln = sys.stdin.readline
rl = lambda : rln().rstrip('\n')
rfs = lambda : rln().split()
mod = 1000000007
d4 = [(0, -1), (1, 0), (0, 1), (-1, 0)]
d8 = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]
t = ri()
for _ in range(t):
	m = ri()
	r = accumulate([0] + ris())
	n = ri()
	b = accumulate([0] + ris())
	print(max(0, max(r) + max(b)))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	m = int(input())
	k = list(map(int, input().split()))
	for i in range(1, n):
		l[i] += l[i - 1]
	for i in range(1, m):
		k[i] += k[i - 1]
	print(max(max(l), max(k), 0, max(l) + max(k)))


from typing import List
from itertools import accumulate
INF = float('inf')
NINF = float('-inf')

def read_string():
	return input()

def read_string_line():
	return [x for x in input().split(' ')]

def read_int_line():
	return [int(x) for x in input().split(' ')]

def read_int():
	return int(input())

def get_int_arr(s):
	return [int(x) for x in s.split()]

def get_sum(acc, l, r):
	return acc[r] - acc[l]
P = int(1000000000.0 + 7)

def exgcd(x, y):
	if y == 0:
		return (x, 1, 0)
	(g, a, b) = exgcd(y, x % y)
	t = x // y
	return (g, b, a - t * b)

def inv(x):
	(g, a, b) = exgcd(x, P)
	return a

def calc_acc(arr):
	ans = [0]
	for a in arr:
		ans.append(a + ans[-1])
	return ans
lines: List[str] = [*open(0)]
for i in range(1, len(lines), 4):
	a = get_int_arr(lines[i + 1])
	b = get_int_arr(lines[i + 3])
	print(max(calc_acc(a)) + max(calc_acc(b)))


def ccc(l):
	ans = [0]
	m = 0
	for i in l:
		m += i
		ans.append(m)
	return max(ans)

def solve():
	n = int(input())
	ln = list(map(int, input().split()))
	m = int(input())
	lm = list(map(int, input().split()))
	return max(0, ccc(ln) + ccc(lm))
for _ in range(int(input())):
	print(solve())


from math import *
from math import factorial as fact, comb as ncr
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def solve():
	for _ in range(int(input())):
		n = int(input())
		r = li()
		for i in range(1, n):
			r[i] += r[i - 1]
		m = int(input())
		b = li()
		for i in range(1, m):
			b[i] += b[i - 1]
		print(max(max(r) + max(b), 0, max(r), max(b)))
solve()


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	m = int(input())
	b = [int(x) for x in input().split()]
	dp = [[-10 ** 9 for j in range(m + 1)] for i in range(n + 1)]
	dp[0][0] = 0
	ans = 0
	for i in range(n + 1):
		for j in range(m + 1):
			if i < n:
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a[i])
			if j < m:
				dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + b[j])
			ans = max(ans, dp[i][j])
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(c1, s1) = (0, 0)
	input()
	for i in map(int, input().split()):
		c1 += i
		if s1 < c1:
			s1 = c1
	(c2, s2) = (0, 0)
	input()
	for i in map(int, input().split()):
		c2 += i
		if s2 < c2:
			s2 = c2
	print(s1 + s2)


for i in range(int(input())):
	n = input()
	lst1 = list(map(int, input().split()))
	m = input()
	lst2 = list(map(int, input().split()))
	s = s1 = mx1 = mx2 = 0
	for i in lst1:
		s += i
		mx1 = max(mx1, s)
	for i in lst2:
		s1 += i
		mx2 = max(mx2, s1)
	print(mx1 + mx2)


for t in range(int(input())):
	l = int(input())
	l = list(map(int, input().split()))
	sum_ = 0
	maxi_a = 0
	for i in l:
		sum_ += i
		if sum_ > maxi_a:
			maxi_a = sum_
	l = int(input())
	l = list(map(int, input().split()))
	sum_ = 0
	maxi_b = 0
	for i in l:
		sum_ += i
		if sum_ > maxi_b:
			maxi_b = sum_
	print(maxi_a + maxi_b)


def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
for _ in range(ii()):
	n = ii()
	a = li()
	m = ii()
	b = li()
	pre = [0] * n
	pre1 = [0] * m
	for i in range(n):
		if i > 0:
			pre[i] += pre[i - 1]
		pre[i] += a[i]
	for i in range(m):
		if i > 0:
			pre1[i] += pre1[i - 1]
		pre1[i] += b[i]
	ans = 0
	for i in range(n):
		ans = max(ans, pre[i])
	for i in range(m):
		ans = max(ans, pre1[i])
	for i in range(n):
		for j in range(m):
			ans = max(ans, pre[i] + pre1[j])
	print(ans)


t = int(input())

def arrayMax(a):
	maxi = 0
	value = 0
	for x in a:
		value += x
		if value > maxi:
			maxi = value
	return maxi
while t > 0:
	t -= 1
	ans = 0
	a = input()
	ans += arrayMax(list(map(int, input().split())))
	b = input()
	ans += arrayMax(list(map(int, input().split())))
	print(ans)


from itertools import *
f = lambda : max(0, *accumulate(map(int, input().split())))
for _ in [0] * f():
	f()
	r = f()
	f()
	print(r + f())


t = int(input())
for case in range(t):
	n = int(input())
	r = [int(x) for x in input().split(' ')]
	m = int(input())
	b = [int(x) for x in input().split(' ')]
	pa = [0]
	for x in r:
		pa.append(pa[-1] + x)
	pb = [0]
	for y in b:
		pb.append(pb[-1] + y)
	ans = max(pa) + max(pb)
	print(ans)


def solve(r, b, n, m):
	ri = []
	bi = []
	for i in range(n):
		try:
			ri.append(ri[-1] + r[i])
		except:
			ri.append(r[0])
	for i in range(m):
		try:
			bi.append(bi[-1] + b[i])
		except:
			bi.append(b[0])
	return max(0, max(ri), max(bi), max(ri) + max(bi))
t = int(input())
while t:
	t -= 1
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	print(solve(r, b, n, m))


t = int(input())
for _ in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	a = r + b
	sub_r = []
	tmp = 0
	for i in range(n):
		tmp += r[i]
		sub_r.append(tmp)
	tmp = 0
	sub_b = []
	for i in range(m):
		tmp += b[i]
		sub_b.append(tmp)
	print(max(0, max(sub_r), max(sub_b), max(sub_r) + max(sub_b)))


t = int(input())
for i in range(t):
	n = int(input())
	r = [int(x) for x in input().split()]
	m = int(input())
	b = [int(x) for x in input().split()]
	a = [r[0]]
	aa = [b[0]]
	for j in range(1, n):
		a.append(r[j] + a[j - 1])
	for j in range(1, m):
		aa.append(b[j] + aa[j - 1])
	alp = max(a)
	print(max(0, max(max(alp, alp + max(aa)), max(max(aa), max(aa) + alp))))


from collections import defaultdict, deque
from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	l = list(map(int, stdin.readline().strip().split()))
	m = int(stdin.readline())
	li = list(map(int, stdin.readline().strip().split()))
	(a, b) = ([0] * n, [0] * m)
	(a[0], b[0]) = (l[0], li[0])
	for i in range(1, n):
		a[i] = a[i - 1] + l[i]
	for i in range(1, m):
		b[i] = b[i - 1] + li[i]
	ans = 0
	x = max(a)
	y = max(b)
	print(max(0, x, y, x + y))


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	maxn = r[0]
	sumn = 0
	for i in range(n):
		sumn = sumn + r[i]
		maxn = max(maxn, sumn)
	maxm = b[0]
	summ = 0
	for i in range(m):
		summ = summ + b[i]
		maxm = max(maxm, summ)
	if maxn <= 0 and maxm <= 0:
		print(0)
	elif maxm <= 0 and maxn > 0:
		print(maxn)
	elif maxn <= 0 and maxm > 0:
		print(maxm)
	else:
		print(maxm + maxn)


tc = int(input())
for _ in range(tc):
	n = int(input())
	l = [int(x) for x in input().split()]
	y = int(input())
	l1 = [int(x) for x in input().split()]
	cur = 0
	sum1 = 0
	for x in range(n):
		if sum1 > cur:
			cur = sum1
		sum1 += l[x]
	if sum1 > cur:
		cur = sum1
	cur1 = 0
	sum2 = 0
	for x in range(y):
		if sum2 > cur1:
			cur1 = sum2
		sum2 += l1[x]
	if sum2 > cur1:
		cur1 = sum2
	maxval = max(cur, cur1, cur + cur1)
	print(maxval)


import sys
input = sys.stdin.readline
for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	s1 = s2 = 0
	for i in range(n + 1):
		s1 = max(s1, sum(a[:i]))
	for i in range(m + 1):
		s2 = max(s2, sum(b[:i]))
	print(s1 + s2)


import sys

def input():
	return sys.stdin.readline().strip()

def solve():
	for t in range(int(input())):
		n = int(input())
		r = list(map(int, input().split()))
		m = int(input())
		b = list(map(int, input().split()))
		s = 0
		rs = [0]
		for i in r:
			s += i
			rs.append(s)
		s = 0
		bs = [0]
		for i in b:
			s += i
			bs.append(s)
		print(max(rs) + max(bs))
solve()


mod = 10 ** 9 + 7

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	sa = [0]
	sb = [0]
	for x in a:
		sa.append(sa[-1] + x)
	for x in b:
		sb.append(sb[-1] + x)
	print(max(sa) + max(sb))
t = 1
t = int(input())
while t > 0:
	solve()
	t -= 1


for _ in range(int(input())):
	ans = 0
	for i in range(2):
		n = int(input())
		l = list(map(int, input().split(' ')))
		for j in range(1, n):
			l[j] += l[j - 1]
		ans += max(0, max(l))
	print(ans)
arr_inp = lambda : list(map(int, input().split()))
sp_inp = lambda : map(int, input().split())
str_inp = lambda : input()


from __future__ import division, print_function
import os
import sys
from sys import stdin, stdout
from io import BytesIO, IOBase
from collections import deque
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		m = int(input())
		b = list(map(int, input().split()))
		dp = [[-10 ** 9 for j in range(m + 1)] for i in range(n + 1)]
		dp[0][0] = 0
		ans = 0
		for i in range(n + 1):
			for j in range(m + 1):
				if i < n:
					dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a[i])
				if j < m:
					dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + b[j])
				ans = max(ans, dp[i][j])
		print(ans)
main()


innum = lambda : int(input())
inmul = lambda : map(int, input().split())
instr = lambda : str(input())
inarr = lambda : list(map(int, input().split()))

def solve():
	n = innum()
	a = inarr()
	m = innum()
	b = inarr()
	mxa = 0
	mxb = 0
	s = 0
	for i in a:
		s += i
		mxa = max(mxa, s)
	s = 0
	for i in b:
		s += i
		mxb = max(mxb, s)
	print(mxa + mxb)

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


import random

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		r = list(map(int, input().split()))
		m = int(input())
		b = list(map(int, input().split()))
		i = 0
		j = 0
		s = 0
		while i != n:
			if r[i] >= 0:
				s += r[i]
				i += 1
			else:
				sr = 0
				while i != n and sr <= 0:
					sr += r[i]
					i += 1
				if sr > 0:
					s += sr
		while j != m:
			if b[j] >= 0:
				s += b[j]
				j += 1
			else:
				sb = 0
				while j != m and sb <= 0:
					sb += b[j]
					j += 1
				if sb > 0:
					s += sb
		print(s)
main()


def func(x):
	s = 0
	maxs = 0
	for i in x:
		s += i
		if s > maxs:
			maxs = s
	return maxs
for t in range(int(input())):
	n = int(input())
	r = [int(i) for i in input().split()]
	m = int(input())
	b = [int(i) for i in input().split()]
	print(func(r) + func(b))


t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	p1 = [0]
	for i in range(n):
		p1.append(p1[-1] + r[i])
	p2 = [0]
	for j in range(m):
		p2.append(p2[-1] + b[j])
	print(max(p1) + max(p2))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	for (idx, n) in enumerate(a[1:], 1):
		a[idx] = a[idx - 1] + n
	for (idx, n) in enumerate(b[1:], 1):
		b[idx] = b[idx - 1] + n
	print(max(0, max(a) + max(b), max(a), max(b)))


t = int(input())
for _ in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	dp1 = [0] * n
	dp2 = [0] * m
	dp1[0] = r[0]
	dp2[0] = b[0]
	ans = 0
	for i in range(1, n):
		dp1[i] = dp1[i - 1] + r[i]
	for i in range(1, m):
		dp2[i] = dp2[i - 1] + b[i]
	d1 = max(dp1)
	d2 = max(dp2)
	ans = max(0, max(d1, 0) + max(d2, 0))
	print(ans)


from sys import stdin, stdout
import math
import heapq
t = 1

def aint():
	return int(input().strip())

def lint():
	return list(map(int, input().split()))

def fint():
	return list(map(int, stdin.readline().split()))

def main():
	n = aint()
	a = lint()
	m = aint()
	b = lint()
	ans = 0
	(l1, l2) = ([0], [0])
	s = 0
	for i in range(n):
		s += a[i]
		l1.append(s)
	s = 0
	for i in range(m):
		s += b[i]
		l2.append(s)
	for i in l1:
		for j in l2:
			ans = max(ans, i + j)
	print(ans)
t = int(input())
for i in range(t):
	main()


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	pr = [0]
	pb = [0]
	for i in r:
		pr.append(i + pr[-1])
	for i in b:
		pb.append(i + pb[-1])
	ans = max(pr) + max(pb)
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
tc = 1
(tc,) = inp()
for _ in range(tc):
	(n,) = inp()
	a = [0] + inp()
	(m,) = inp()
	b = [0] + inp()
	for i in range(1, len(a)):
		a[i] += a[i - 1]
	for i in range(1, len(b)):
		b[i] += b[i - 1]
	print(max(a) + max(b))


import math
import bisect
from collections import defaultdict
from collections import OrderedDict
from itertools import combinations
for _ in range(int(input())):
	n = int(input())
	an = list(map(int, input().split()))
	m = int(input())
	am = list(map(int, input().split()))
	ans = sum(an) + sum(am)
	n1 = 0
	m1 = 0
	temp = 0
	for i in range(n):
		temp += an[i]
		n1 = max(n1, temp)
	temp = 0
	for i in range(m):
		temp += am[i]
		m1 = max(m1, temp)
	print(max(m1 + n1, ans))


t = int(input())
for i in range(0, t):
	n = int(input())
	red = [int(i) for i in input().split()]
	m = int(input())
	blue = [int(i) for i in input().split()]
	red_max = ssum = 0
	for j in range(0, n):
		ssum += red[j]
		red_max = max(red_max, ssum)
	blue_max = ssum = 0
	for j in range(0, m):
		ssum += blue[j]
		blue_max = max(blue_max, ssum)
	print(red_max + blue_max)


import sys
import itertools
import math
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(k,) = I()
while k:
	k -= 1
	(n,) = I()
	arr = I()
	s = []
	s.append(0)
	j = 0
	for i in arr:
		j += i
		s.append(j)
	(m,) = I()
	brr = I()
	t = []
	t.append(0)
	j = 0
	for i in brr:
		j += i
		t.append(j)
	print(max(s) + max(t))


def solve():
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	res = 0
	prev = 0
	maxim = 0
	for el in r:
		prev += el
		maxim = max(maxim, prev)
	res += maxim
	prev = 0
	maxim = 0
	for el in b:
		prev += el
		maxim = max(maxim, prev)
	res += maxim
	print(res)
	return
t = int(input())
for _ in range(t):
	solve()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = int(input())
	len1 = len(a)
	b = list(map(int, input().split()))
	ma = a[0]
	ma1 = b[0]
	s = 0
	s1 = 0
	for i in range(len(a)):
		s += a[i]
		if s > ma:
			ma = s
	for i in range(len(b)):
		s1 += b[i]
		if s1 > ma1:
			ma1 = s1
	t = max(0, ma) + max(0, ma1)
	print(t)


T = int(input())
for t in range(T):
	n = int(input())
	r = list(map(int, input().split()))
	for i in range(1, n):
		r[i] += r[i - 1]
	a = max(r)
	m = int(input())
	b = list(map(int, input().split()))
	for i in range(1, m):
		b[i] += b[i - 1]
	c = max(b)
	print(max(0, a, c, a + c))


tt = int(input())
for tt2 in range(tt):
	n = int(input())
	t = list(map(int, input().split()))
	m = int(input())
	t2 = list(map(int, input().split()))
	(s1, s2, cur) = (0, 0, 0)
	for i in range(n):
		cur += t[i]
		s1 = max(s1, cur)
	cur = 0
	for i in range(m):
		cur += t2[i]
		s2 = max(s2, cur)
	print(s1 + s2)


def prefixSum(array):
	total = 0
	maximum = 0
	for j in range(len(array)):
		total += array[j]
		maximum = max(maximum, total)
	return maximum

def listInput():
	return list(map(int, input().split()))

def integerInput():
	return int(input())
test_cases = int(input())
for _ in range(test_cases):
	(n, red) = (integerInput(), listInput())
	(m, blue) = (integerInput(), listInput())
	print(prefixSum(red) + prefixSum(blue))


def readInt():
	return int(input())

def readLine():
	return [int(s) for s in input().split(' ')]

def readString():
	return input()

def ask(a, b):
	maxsuma = 0
	suma = 0
	for x in a:
		suma += x
		if suma > maxsuma:
			maxsuma = suma
	maxsumb = 0
	sumb = 0
	for x in b:
		sumb += x
		if sumb > maxsumb:
			maxsumb = sumb
	return maxsuma + maxsumb
t = readInt()
for _ in range(t):
	a = readInt()
	aa = readLine()
	b = readInt()
	bb = readLine()
	print(ask(aa, bb))


for i in range(int(input())):
	input()
	n = list(map(int, input().split()))
	input()
	m = list(map(int, input().split()))
	n1 = [0]
	m1 = [0]
	n2 = 0
	m2 = 0
	for z in n:
		n2 += int(z)
		n1.append(n2)
	for j in m:
		m2 += int(j)
		m1.append(m2)
	print(max(n1) + max(m1))


for _ in range(int(input())):
	n = int(input())
	red = list(map(int, input().split()))
	m = int(input())
	blue = list(map(int, input().split()))
	max_red = 0
	max_blue = 0
	cur_sum = 0
	for i in range(n):
		cur_sum += red[i]
		max_red = max(max_red, cur_sum)
	cur_sum = 0
	for j in range(m):
		cur_sum += blue[j]
		max_blue = max(max_blue, cur_sum)
	print(max_red + max_blue)


for k in range(int(input())):
	input()
	a = list(map(int, input().split()))
	ca = 0
	s = 0
	for e in a:
		s += e
		ca = max(ca, s)
	input()
	b = list(map(int, input().split()))
	cb = 0
	s = 0
	for e in b:
		s += e
		cb = max(cb, s)
	print(ca + cb)


import itertools
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	m = int(input())
	y = list(map(int, input().split()))
	a = list(itertools.accumulate(x))
	b = list(itertools.accumulate(y))
	print(max(0, max(a)) + max(0, max(b)))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
from collections import *
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		m = ii()
		b = li()
		mpa = 0
		s = 0
		for ele in a:
			mpa = max(mpa, s + ele)
			s += ele
		mpb = 0
		s = 0
		for ele in b:
			mpb = max(mpb, s + ele)
			s += ele
		print(max(mpa, mpb, mpa + mpb))
main()


for k in range(int(input())):
	answer = 0
	for i in range(2):
		n = int(input())
		l = list(map(int, input().split(' ')))
		for j in range(1, n):
			l[j] += l[j - 1]
		answer += max(0, max(l))
	print(answer)


import math
import sys
import bisect
from heapq import heapify, heappop, heappush
from itertools import *
from collections import deque, OrderedDict
from pprint import pprint
sys.setrecursionlimit(10 ** 6)
II = lambda : sys.stdin.readline()
inp = lambda : int(II())
inpm = lambda : map(int, II().split())
inpl = lambda : list(inpm())
arr_mn = lambda _n, _m: [[0 for __ in range(_m)] for _ in range(_n)]
arr_nn = lambda _n: arr_mn(_n, _n)
(WHITE, GREY, BLACK, RED) = (0, 1, 2, 3)
EPS = 1e-09
INF = 1000000001
MOD = int(1000000000.0) + 7
N = 2000009

def solve():
	n = inp()
	a = inpl()
	m = inp()
	b = inpl()
	x = 0
	p = 0
	for i in range(n):
		p += a[i]
		x = max(p, x)
	y = 0
	p = 0
	for i in range(m):
		p += b[i]
		y = max(p, y)
	print(x + y)

def main():
	t = inp()
	for i in range(t):
		solve()
main()


for _ in range(int(input())):
	n = int(input())
	r = list(map(int, input().split()))
	m = int(input())
	b = list(map(int, input().split()))
	(rm, bm) = (0, 0)
	(rc, bc) = (0, 0)
	for i in range(n):
		rm = max(rm, rc + r[i])
		rc += r[i]
	for i in range(m):
		bm = max(bm, bc + b[i])
		bc += b[i]
	print(rm + bm)


import math
import collections
import itertools
import functools

def fun(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	m = int(input())
	b = list(map(int, input().split(' ')))
	sumi = 0
	m1 = 0
	for i in range(n):
		sumi += a[i]
		m1 = max(m1, sumi)
	sumi = 0
	m2 = 0
	for i in range(m):
		sumi += b[i]
		m2 = max(m2, sumi)
	print(max(m1 + m2, max(m1, max(0, m2))))
for tc in range(int(input())):
	fun(tc)


from itertools import accumulate as acc
for _ in range(int(input())):
	n = int(input())
	a1 = list(acc(map(int, input().split())))
	m = int(input())
	a2 = list(acc(map(int, input().split())))
	print(max(a1 + [0]) + max(a2 + [0]))


n = int(input())
z = 0
while z < n:
	nr = int(input())
	lsta = list(map(int, input().split()))
	nb = int(input())
	lstb = list(map(int, input().split()))
	max1 = 0
	max2 = 0
	sum1 = 0
	sum2 = 0
	for i in lsta:
		sum1 += i
		if sum1 > max1:
			max1 = sum1
	for i in lstb:
		sum2 += i
		if sum2 > max2:
			max2 = sum2
	print(str(max1 + max2))
	z += 1


n = int(input())
for j in range(n):
	r = int(input())
	red = list(map(int, input().split()))
	b = int(input())
	blue = list(map(int, input().split()))
	dpr = [0] * r
	dpb = [0] * b
	dpr[0] = red[0]
	dpb[0] = blue[0]
	for i in range(1, r):
		dpr[i] = dpr[i - 1] + red[i]
	for i in range(1, b):
		dpb[i] = dpb[i - 1] + blue[i]
	print(max(max(dpb), 0) + max(max(dpr), 0))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	n = int(input())
	b = list(map(int, input().split()))
	sum = 0
	ma1 = 0
	for p in a:
		sum += p
		ma1 = max(ma1, sum)
	sum = 0
	ma2 = 0
	for j in b:
		sum += j
		ma2 = max(ma2, sum)
	print(ma1 + ma2)


t = int(input())
for i in range(t):
	n = int(input())
	r = list(map(int, input().split()))
	a = 0
	c = 0
	for j in r:
		c += j
		if c > a:
			a = c
	m = int(input())
	b = list(map(int, input().split()))
	d = 0
	e = 0
	for j in b:
		e += j
		if e > d:
			d = e
	print(a + d)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	m = int(input())
	b = [int(x) for x in input().split()]
	sum1 = []
	sum2 = []
	sum = 0
	ma1 = 0
	ma2 = 0
	for i in range(n):
		sum += a[i]
		sum1.append(sum)
		ma1 = max(ma1, sum)
	sum = 0
	for i in range(m):
		sum += b[i]
		sum2.append(sum)
		ma2 = max(ma2, sum)
	print(ma1 + ma2)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	m = int(input())
	l2 = list(map(int, input().split()))
	s = 0
	m = 0
	t = 0
	for i in l1:
		s += i
		m = max(m, s)
	t = m
	s = 0
	m = 0
	for i in l2:
		s += i
		m = max(m, s)
	print(t + m)


for t in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	m = int(input())
	B = list(map(int, input().split()))
	for i in range(1, n):
		A[i] += A[i - 1]
	for i in range(1, m):
		B[i] += B[i - 1]
	print(max(0, max(0, max(A)) + max(0, max(B))))


t = int(input())
i = 0
while i < t:
	n = int(input())
	red = list(map(int, input().split()))
	m = int(input())
	blue = list(map(int, input().split()))
	sum1 = -0
	sum2 = -0
	j = 0
	sum11 = 0
	while j < n:
		sum11 += red[j]
		if sum11 > sum1:
			sum1 = sum11
		j += 1
	j = 0
	sum22 = 0
	while j < m:
		sum22 += blue[j]
		if sum22 > sum2:
			sum2 = sum22
		j += 1
	print(sum1 + sum2)
	i += 1


class Solution:

	def getMax(self, red, n, blue, m):
		mx1 = 0
		local = 0
		for x in red:
			local += x
			mx1 = max(mx1, local)
		mx2 = 0
		local = 0
		for x in blue:
			local += x
			mx2 = max(mx2, local)
		print(mx1 + mx2)
		return

def main():
	t = int(input())
	sol = Solution()
	while t:
		n = int(input())
		red = list(map(int, input().strip().split()))
		m = int(input())
		blue = list(map(int, input().strip().split()))
		sol.getMax(red, n, blue, m)
		t -= 1
main()