#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int a[N], b[N], dp[N][N];
int main(){
int t;
cin >> t;
while(t --){
int n;
cin >> n;
for(int i = 1; i <= n; i ++)
cin >> a[i];
for(int i = 1; i <= n; i ++)
cin >> b[i];
for(int i = 1; i <= n; i ++)
dp[i][i] = a[i] * b[n];
for(int i = n; i >= 1; i --){
for(int j = i + 1; j <= n; j ++){
dp[i][j] = max(dp[i+1][j]+a[i]*b[n-(j-i)],dp[i][j-1]+a[j]*b[n-(j-i)]);
}
}
cout << dp[1][n] << endl;
}
return 0;
}