#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(v) begin(v), end(v)
bool check(vector<ll> &a, vector<ll> &b)
{
int n = a.size();
if (n < 3)
return true;
for (int i = 1; i < n - 1; ++i)
if (!((a[i] > b[i - 1] && a[i] > b[i + 1]) ||
(b[i] > a[i - 1] && b[i] > a[i + 1])))
return false;
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
vector<ll> a(n), b(n);
for (auto &x : a)
cin >> x;
for (auto &x : b)
cin >> x;
if (n < 3)
{
cout << "Yes\n";
continue;
}
sort(all(a));
sort(all(b));
bool f = false;
for (int m = 0; m < 4 && !f; ++m)
{
auto ta = a;
auto tb = b;
if (m % 2 == 1)
reverse(all(ta));
if (m & 2)
reverse(all(tb));
f = check(ta, tb);
}
f ? cout << "Yes\n" : cout << "No\n";
}
}