#include <bits/stdc++.h>
using namespace std;
void pVec(vector<int> f){
for(auto i : f) cout << i << " ";
cout << endl;
}
int main() {
int t,n; cin >> t;
while(t--){
cin >> n;
vector<int> a(n),b(n);
for(int i=0;i<n;i++) cin >> a[i];
for(int i=0;i<n;i++) cin >> b[i];
int mxa = *max_element(a.begin(),a.end()), mxb = *max_element(b.begin(),b.end());
if(mxa >= mxb) for(int i=0;i<n;i++){ if(a[i] <= b[i]) swap(a[i],b[i]);}
else for(int i=0;i<n;i++){ if(a[i] > b[i]) swap(a[i],b[i]);}
mxa = *max_element(a.begin(),a.end()), mxb = *max_element(b.begin(),b.end());
cout << mxa * mxb << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIHBWZWModmVjdG9yPGludD4gZil7Cglmb3IoYXV0byBpIDogZikgY291dCA8PCBpIDw8ICIgIjsKCWNvdXQgPDwgZW5kbDsKfQppbnQgbWFpbigpIHsKCWludCB0LG47IGNpbiA+PiB0OwoJd2hpbGUodC0tKXsKCQljaW4gPj4gbjsKCQkKCQl2ZWN0b3I8aW50PiBhKG4pLGIobik7CgkJZm9yKGludCBpPTA7aTxuO2krKykJY2luID4+IGFbaV07CgkJZm9yKGludCBpPTA7aTxuO2krKykJY2luID4+IGJbaV07CgkJCgkJaW50IG14YSA9ICptYXhfZWxlbWVudChhLmJlZ2luKCksYS5lbmQoKSksIG14YiA9ICptYXhfZWxlbWVudChiLmJlZ2luKCksYi5lbmQoKSk7CgkJCgkJaWYobXhhID49IG14YikJZm9yKGludCBpPTA7aTxuO2krKyl7CWlmKGFbaV0gPD0gYltpXSkgc3dhcChhW2ldLGJbaV0pO30KCQllbHNlCWZvcihpbnQgaT0wO2k8bjtpKyspewlpZihhW2ldID4gYltpXSkgc3dhcChhW2ldLGJbaV0pO30KCQkKCQlteGEgPSAqbWF4X2VsZW1lbnQoYS5iZWdpbigpLGEuZW5kKCkpLCBteGIgPSAqbWF4X2VsZW1lbnQoYi5iZWdpbigpLGIuZW5kKCkpOwoJCWNvdXQgPDwgbXhhICogbXhiIDw8IGVuZGw7Cgl9CglyZXR1cm4gMDsKfQ==