#include <bits/stdc++.h> 
using namespace std; 

#define vec vector 
#define PB push_back 

#define MP make_pair 
#define MT make_tuple 
#define F first 
#define S second 

using ll = long long int; // watch out for overflows in your code
using pii = pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void debug() { cout << "\n"; };
template <typename T, typename... Targs> 
void debug(T t, Targs... args) {
    cout << t << " ";
    debug(args...);
}

template <typename T1, typename T2> 
inline ostream& operator << (ostream& os, const pair<T1,T2>& p) {
    return os << "(" << p.F << ", " << p.S << ")";
}

template <typename T> 
inline ostream& operator << (ostream& os, const vec<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename T> 
inline ostream& operator << (ostream& os, const vec<vec<T>>& m) {
    for(auto& v : m) {
        for(auto& t : v) {
            os << t << " ";
        }
        os << "\n";
    }
    return os;
}

template <typename T> 
inline ostream& operator << (ostream& os, const set<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename K, typename V> 
inline ostream& operator << (ostream& os, const map<K,V>& m) {
    for(auto& p : m) {
        os << p.F << " -> " << p.S << "\n";
    }
    return os;
}

const int INF = 2 * 1e9;
int T, N, M;
vec<int> A, B;

int increment(int& i, const vec<int>& v) {
    int S = v.size();
    if(i >= S) {
        return -INF;
    }
    int P = v[i++];
    while(i < S && P < 0) {
        P += v[i];
        i++;
    }
    while(i < S && P <= P + v[i]) {
        P = P + v[i];
        ++i;
    }
    return P;
}

int compute() {
    int j = 0, i = 0;
    int pa, pb;
    int S = 0;
    int ans = 0;

    pa = increment(i, A);
    pb = increment(j, B);

    while(i <= N || j <= M) {
        //debug("pa", pa, "pb", pb);
        if(pa < 0 && pb < 0) {
            break;
        }
        if(pa >= pb) {
            S += pa;
            pa = increment(i, A);
        }
        else {
            S += pb;
            pb = increment(j, B);
        }
        ans = max(ans, S);
    }
    return ans;
}

////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> T;
    while(T--) {
        cin >> N;
        A.assign(N, 0);
        for(int i = 0; i < N; ++i) {
            cin >> A[i];
        }
        cin >> M;
        B.assign(M, 0);
        for(int j = 0; j < M; ++j) {
            cin >> B[j];
        }
        cout << compute() << "\n";
    }

}

