#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...) 42
#endif
#define int long long
bool solve(vector<int> &a, vector<int> &b) {
multiset<int> s, t;
int n = a.size();
for (int i = 0; i < n; i++) {
s.insert(a[i]);
}
for (int i = 0; i < n; i++) {
t.insert(b[i]);
}
vector<int> c(n, -1), d(n, -1);
for (int i = 1; i < n - 1; i++) {
c[i] = *s.rbegin(); s.erase(prev(s.end()));
if (d[i - 1] == -1) {
auto it = prev(t.upper_bound(c[i]));
if (it == t.end()) return false;
d[i - 1] = *it;
t.erase(it);
}
if (d[i + 1] == -1) {
if (d[i - 1] == -1) {
auto it = prev(t.upper_bound(c[i]));
if (it == t.end()) return false;
d[i + 1] = *it;
t.erase(it);
}
}
}
for (int i = 1; i < n - 1; i++) {
if (c[i] > max(d[i - 1], d[i + 1]) || d[i] > max(c[i - 1], c[i + 1])) {
}
else {
return false;
}
}
return true;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
if (!solve(a, b) && !solve(b, a)) {
cout << "No\n";
}
else {
cout << "Yes\n";
}
}
return 0;
}