/*
* 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){
cout << "Yes" << endl;
return;
}
else if (n == 2){
if (a[1] > b[0] || b[1] > a[1]){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
}
else{
A = a;
B = b;
A.erase(A.begin());
bool ok = true;
for (int i = 1; i < n - 1; i++){
if (A[i] <= b[i - 1]){
ok = false;
break;
}
if (A[i] <= b[i + 1]){
if (i == 1)
swap(b[i], b[i + 1]);
if (A[i] <= b[i + 1]){
ok = false;
break;
}
}
}
if (ok){
cout << "Yes" << endl;
return;
}
ok = true;
B.erase(B.begin());
// for (auto i : B) cout << i << ' ';
for (int i = 1; i < n - 1; i++){
if (B[i] <= a[i - 1]){
ok = false;
break;
}
if (B[i] <= a[i + 1]){
if (i == 1)
swap(a[i], a[i + 1]);
if (B[i] <= a[i + 1]){
ok = false;
break;
}
}
}
if (!ok){
cout << "No" << endl;
}
else{
cout << "Yes" << endl;
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}