/*
* Name : Md. Fahmidur Rahman Nafi
* Date : 2025-06-13 Time : 20:50:23
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ld long double
#define ull unsigned long long
#define lcm(a,b) ((a*b)/__gcd(a,b))
#define debug(x) cout << "Debug : " << x << endl;
const double PI = 2 * acos(0.0);
const int MOD = 1000000007;
void solve(){
int n;
cin >> n;
vector <ll> a(n), b(n), A, B;
for (auto &i : a) cin >> i;
for (auto &i : b) cin >> i;
sort(b.begin(), b.end());
sort(a.begin(), a.end());
if (n == 1 || n == 2){
cout << "Yes" << endl;
}
else{
A = a;
B = b;
if (a.back() == b.back()){
cout << "No" << endl;
}
else if(a.back() > b.back()){ // A boro
int cnt = 0;
for (int i = 0; i < n; i++){
if (a[i] < b[i]){
cnt++;
if (cnt > 2){
cout << "No" << endl;
return;
}
}
}
cout << "Yes" << endl;
}
else{
int cnt = 0;
for (int i = 0; i < n; i++){
if (a[i] > b[i]){
cnt++;
if (cnt > 2){
cout << "No" << endl;
return;
}
}
}
cout << "Yes" << endl;
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}