/*
*Copyright (c) Swadheen Islam Robi (SIR01)
*Created on Sat Jun 14 2025 12:49:52 AM
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pie 2*(acos(0.0))
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define pb push_back
#define endl "\n"
#define lcm(a,b) (a*b)/(__gcd<ll>(a,b))
#define mod 1000000007
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define ALLAHU_AKBAR ios::sync_with_stdio(false); cin.tie(nullptr);
void sir()
{
ll n;
cin >> n;
vector<ll> a(n), b(n), x(n), y(n);
for(auto &e:a) cin>>e;
for(auto &d:b) cin>>d;
srt(a); srt(b);
//peak considering a
x[0] = a[0], x[n-1] = a[1];
ll ind = 2;
for(ll i=1; i<n-1; i+=2) x[i] = a[ind++];
for(ll i=2; i<n-1; i+=2) x[i] = a[ind++];
ind = 0;
for(ll i=0; i<n; i+=2) y[i] = b[ind++];
for(ll i=1; i<n; i+=2) y[i] = b[ind++];
bool ok = true;
for(ll i=1; i<n-1; i++)
{
if(x[i]<=y[i-1]|| x[i]<=y[i+1])
{
ok = false;
break;
}
}
// for(auto &e:x) cout<<e<<" "; cout<<endl;
// for(auto &e:y) cout<<e<<" "; cout<<endl;
if(ok)
{
yes;
return;
}
//peak considering a
x[0] = b[0], x[n-1] = b[1];
ind = 2;
for(ll i=1; i<n-1; i+=2) x[i] = b[ind++];
for(ll i=2; i<n-1; i+=2) x[i] = b[ind++];
ind = 0;
for(ll i=0; i<n; i+=2) y[i] = a[ind++];
for(ll i=1; i<n; i+=2) y[i] = a[ind++];
ok = true;
for(ll i=1; i<n-1; i++)
{
if(x[i]<=y[i-1]|| x[i]<=y[i+1])
{
ok = false;
break;
}
}
// for(auto &e:x) cout<<e<<" "; cout<<endl;
// for(auto &e:y) cout<<e<<" "; cout<<endl;
if(ok)
{
yes;
return;
}
no;
}
int main() {
ALLAHU_AKBAR
ll t = 1;
cin>>t;
while(t--)
{
sir();
}
return 0;
}