#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>

using namespace std;

void ReadArray(vector<int> &arr) {
    for (auto &elem : arr) {
        cin >> elem;
    }
}

void Solve() {
    int n, m;
    cin >> n;
    vector<int> r(n);
    ReadArray(r);
    cin >> m;
    vector<int> b(m);
    ReadArray(b);
    vector<int> prefix_r(n, 0);
    vector<int> prefix_b(m, 0);

    prefix_r[0] = r[0];
    for (int i = 1; i < n; ++i) {
        prefix_r[i] = prefix_r[i - 1] + r[i];
    }

    prefix_b[0] = b[0];
    for (int i = 1; i < m; ++i) {
        prefix_b[i] = prefix_b[i - 1] + b[i];
    }

    int max_prefix_r = max(0, *max_element(prefix_r.begin(), prefix_r.end()));
    int max_prefix_b = max(0, *max_element(prefix_b.begin(), prefix_b.end()));

    int ans = max_prefix_b + max_prefix_r;
    cout << ans << "\n";
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        Solve();
    }

    return 0;
}
