#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define PLL pair<long long, long long>
#define int long long
#define LL long long
#define faster {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define all(v) v.begin(),v.end()
const LL mod = 998244353;
const int N = 1e5 + 10;
const LL INF = 1e17 + 1;
const int inf = 1e9 + 1;
void solve(int tc) {
int n; cin >> n;
vector<int> a(n), b(n);
for(auto &u: a)
cin >> u;
for(auto &u: b)
cin >> u;
auto check = [&](){
sort(all(a));
sort(all(b));
if(n > 2) swap(b[1], b[2]);
for(int i = 2; i < n; i++){
if(a[i] <= b[i - 2] or a[i] <= b[i]) return 0;
}
return 1;
};
bool fl = check(); swap(a, b);
fl |= check();
cout << (fl ? "Yes" : "No") << '\n';
}
signed main() {
faster
int t = 1;
cin >> t;
for (int tc = 1; tc <= t; tc++) {
solve(tc);
}
return 0;
}