t=int(input())
for inh in range(0,t):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(0,n):
x,y=a[i],b[i]
a[i]=max(x,y)
b[i]=min(x,y)
print(max(a)*max(b))
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int arr1[n],arr2[n];
int index1,index2;
int max1 = INT_MIN,max2=INT_MIN;
int ans = 0;
for(int i=0;i<n;i++){
cin>>arr1[i];
}
for(int i=0;i<n;i++){
cin>>arr2[i];
}
for(int i=0;i<n;i++){
if(arr1[i] < arr2[i]){
swap(arr1[i],arr2[i]);
}
}
for(int i=0;i<n;i++){
if(max1 < arr1[i]){
max1=arr1[i];
index1=i;
}
}
for(int i=0;i<n;i++){
if(max2 < arr2[i]){
max2 = arr2[i];
index2 = i;
}
}
cout<< max1 * max2 <<endl;
}
return 0;
}
236A - Boy or Girl | 271A - Beautiful Year |
520B - Two Buttons | 231A - Team |
479C - Exams | 1030A - In Search of an Easy Problem |
158A - Next Round | 71A - Way Too Long Words |
160A - Twins | 1A - Theatre Square |
1614B - Divan and a New Project | 791A - Bear and Big Brother |
1452A - Robot Program | 344A - Magnets |
96A - Football | 702B - Powers of Two |
1036A - Function Height | 443A - Anton and Letters |
1478B - Nezzar and Lucky Number | 228A - Is your horseshoe on the other hoof |
122A - Lucky Division | 1611C - Polycarp Recovers the Permutation |
432A - Choosing Teams | 758A - Holiday Of Equality |
1650C - Weight of the System of Nested Segments | 1097A - Gennady and a Card Game |
248A - Cupboards | 1641A - Great Sequence |
1537A - Arithmetic Array | 1370A - Maximum GCD |