import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

int best (int [] a)
{
	int res = 0;
	int cur = 0;
	foreach (ref c; a)
	{
		cur += c;
		res = max (res, cur);
	}
	return res;
}

int solve (int [] r, int [] b)
{
	return best (r) + best (b);
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto r = readln.splitter.map !(to !(int)).array;
		auto m = readln.strip.to !(int);
		auto b = readln.splitter.map !(to !(int)).array;
		writeln (solve (r, b));
	}
}
