#include <bits/stdc++.h>
#ifdef LOCAL
#include "../algo/debug.h"
#else
#define debug(...) 0
#endif
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> n;
vector a(2, vector<long long> (n + 1));
for (int j = 0; j < 2; j++) {
for (int i = 1; i <= n; i++) {
cin >> a[j][i];
}
}
long long inf = 8e18;
vector f(2, vector<long long> (n + 1, -inf));
for (int j = 0; j < 2; j++) {
long long mx = -inf;
for (int i = 1; i <= n; i++) {
if (i == 1 && j == 0) {
f[j][i] = a[j][i] * 2;
continue;
}
if (i > 1) {
f[j][i] = max(f[j][i], f[j][i - 1] + a[j][i] * 2);
}
if (j > 0) {
f[j][i] = max(f[j][i], f[j - 1][i] + a[j][i] * 2);
}
if (i > 1) {
mx = max(mx, f[j][i - 1] + i - 1 + (i - 1) * 1ll * (i - 1));
f[j][i] = max(f[j][i], mx - i * 1ll * i + i + a[j][i] * 2);
}
}
}
cout << f[1][n] / 2 << '\n';
}
return 0;
}