#include <bits/stdc++.h>
using namespace std;
bool check(vector<int> a, vector<int> b) {
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int n = a.size();
for (int i = 2, j = 0; i < n; i++, j++) {
if (a[i] <= b[j + 2]) {
return false;
}
}
return true;
}
void solve(int cs) {
int n;
cin >> n;
vector<int> a(n), b(n);
for (auto &i : a) cin >> i;
for (auto &i : b) cin >> i;
if (n < 3) {
cout << "Yes\n";
return;
}
cout << (check(a, b) || check(b, a) ? "Yes\n" : "No\n");
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(0);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
solve(i);
}
return 0;
}