#include <bits/stdc++.h>
using namespace std;
#define int long long
void iusearchbtw () {
int n; cin >> n;
vector<int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
sort(a.begin() + 1, a.end());
sort(b.begin() + 1, b.end());
bool ok1 = 1, ok2 = 1;
for (int i = 1; i <= n; i++) {
ok1 &= (a[i] > b[i]);
ok2 &= (a[i] < b[i]);
}
cout << (n == 1 || ok1 || ok2 ? "Yes\n" : "No\n");
}
signed main () {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
cin >> tt;
while (tt --> 0) iusearchbtw();
}