//Don't Panic
//Read the q properly
//Don't see the standings until the contest is over.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vsum(v) accumulate(v.begin(),v.end(),0LL)
#define maxi(v) *max_element(v.begin(),v.end())
#define mini(v) *min_element(v.begin(),v.end())
#define sort(v) sort(v.begin(),v.end())
const int N=1e7+10;
// vector<bool> isPrime(N,1);
// vector<int> hp(N,0),lp(N,0);
//a+b=(a ^b)+2.(a&b)
//function to check whether a given number is prime or not
bool checkPrime(int n) {
if (n<=1) return false;
if (n<=3) return true;
if (n%2==0 || n%3==0) return false;
for(int i=5; i*i<=n;i+=6) {
if(n%i==0 || n%(i+2)==0)
return false;
}
return true;
}
//sieve
// void sieve(){
// isPrime[0]=isPrime[1]=false;
// for(int i=2;i<N;i++){
// if(isPrime[i]==true){
// lp[i]=hp[i]=i;
// for(int j=2*i;j<N;j+=i){
// isPrime[j]=false;
// hp[j]=i;
// if(lp[j]==0){
// lp[j]=i;
// }
// }
// }
// }
// }
void solve(){
//code yaha par likh
int n;
cin>>n;
vector<int> a(n);
vector<int> b(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n;i++){
cin>>b[i];
}
if(n<3){
cout<<"Yes"<<endl;
return;
}
sort(a);
sort(b);
if(a[0]==b[0] || a[n-1]==b[n-1]) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// int t=1;
int t;cin>>t;
while(t--){
solve();
}
}