constint N = 200005; int pr[N], te[N]; int zhiye[N];
voidsolve() { int n, m; cin >> n >> m; int pr_cnt = 0, te_cnt = 0; int total = n + m + 1; int full_pr = 0, full_te = 0; bool isfull_pr = false, isfull_te = false; if (n == 0) isfull_pr = true; if (m == 0) isfull_te = true; LL as = 0; for (int i = 0; i < total; ++i) { cin >> pr[i]; } for (int i = 0; i < total; ++i) { cin >> te[i]; } for (int i = 0; i < total - 1; ++i) { if (pr[i] > te[i]) { if (pr_cnt <= n && !isfull_pr) { as += pr[i]; pr_cnt++; zhiye[i] = 0; if (pr_cnt == n) { full_pr = i; isfull_pr = true; } } else { as += te[i];
te_cnt++; zhiye[i] = 1; if (te_cnt == m) { full_te = i; isfull_te = true; } } } else { if (te_cnt <= m && !isfull_te) { as += te[i];
te_cnt++; zhiye[i] = 1; if (te_cnt == m) { full_te = i; isfull_te = true; } } else { as += pr[i]; pr_cnt++; zhiye[i] = 0; if (pr_cnt == n) { full_pr = i; isfull_pr = true; } } } } for (int i = 0; i < total - 1; ++i) { bool flag2 = false; LL ans = as; if (zhiye[i] == 0) { ans -= pr[i]; if (i > full_te) { ans += pr[total - 1]; } else { for (int j = full_pr + 1; j < total - 1; j++) { if (pr[j] > te[j]) { ans = ans + pr[j] - te[j]; flag2 = true; break; } } if (flag2) { ans += te[total - 1]; } else { ans += pr[total - 1]; } } } else { ans -= te[i]; if (i > full_pr) { ans += te[total - 1]; } else { for (int j = full_te + 1; j < total - 1; j++) { if (pr[j] < te[j]) { ans = ans - pr[j] + te[j]; flag2 = true; break; } } if (flag2) { ans += pr[total - 1]; } else { ans += te[total - 1]; } } }
cout << ans << ' '; } cout << as << endl; return; } intmain() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { solve(); } return0; }