/*
*Copyright (c) Swadheen Islam Robi (SIR01)
*Created on Fri Jun 13 2025 8:30:16 PM
*/
#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 sir1()
// {
// ll n; cin>>n;
// ll x = sqrt(n);
// ll ans = 0;
// for(ll i =1; i<=x; i++)
// {
// ll j = i+1;
// if(i*i<=n) ans++;
// if(i*j<=n) ans++;
// }
// cout<<ans<<endl;
// }
// void sir2()
// {
// ll a,b,c; cin>>a>>b>>c;
// ll cnt = 0;
// ll ans;
// if(a%2)cnt++;
// if(b%2)cnt++;
// if(c%2)cnt++;
// if(cnt<2) ans = a+b+c;
// else if(cnt==2) ans = (a+b+c)-1;
// else ans = (a+b+c)-2;
// cout<<ans<<endl;
// }
bool val(const vector<ll>&A,const vector<ll>&B,ll n){
for(ll 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;
}
void sir3() {
ll n; cin >> n;
vector<ll> a(n), b(n);
for (auto &e : a) cin >> e;
for (auto &d : b) cin >> d;
if (n <= 2) {
yes;
return;
}
vector<ll> A1 = a, B1 = b;
rsrt(A1); srt(B1);
// ll tem = A1[0];
// A1[0] = A1[n-1];
// for(ll i=1; i<n; i++)
// {
// ll tt = A1[i];
// A1[i] = tem;
// tem = tt;
// }
// for(ll i=0; i<n; i++) cout<<A1[i]<<" ";cout<<endl;
// for(ll i=0; i<n; i++) cout<<B1[i]<<" ";cout<<endl;
if (val(A1, B1, n)) {
yes;
return;
}
vector<ll> A2 = a, B2 = b;
srt(A2); rsrt(B2);
// tem = B2[0];
// B2[0] = B2[n-1];
// for(ll i=1; i<n; i++)
// {
// ll tt = B2[i];
// B2[i] = tem;
// tem = tt;
// }
// for(auto &e:B2) cout<<e<<" "; cout<<endl;
// for(auto &e:A2) cout<<e<<" ";
if (val(B2, A2, n)) {
yes;
return;
}
no;
}
void sir33()
{
ll n; cin >> n;
vector<ll> a(n), b(n);
for (auto &e : a) cin >> e;
for (auto &d : b) cin >> d;
if (n <= 2) {
yes;
return;
}
vector<ll> aa = a, bb = b;
srt(aa); srt(bb);
map<ll,ll>mp;
for(ll i=0; i<n;i++)
{
auto it = upper_bound(aa.begin(), aa.end(), bb[i]);
if(it != aa.end())
{
aa.erase(it);
mp[*it]++;
}
}
bool ok = true;
for(auto &[x,y]:mp)
{
if(y!=2)
{
ok = false;
break;
}
}
if(ok)
{
yes; return;
}
srt(a); srt(b);
map<ll,ll>mp2;
for(ll i=0; i<n;i++)
{
auto it = upper_bound(b.begin(), b.end(), a[i]);
if(it != b.end())
{
b.erase(it);
mp2[*it]++;
}
}
ok = true;
for(auto &[x,y]:mp2)
{
if(y!=2)
{
ok = false;
break;
}
}
if(ok)
{
yes; return;
}
no;
}
int main() {
ALLAHU_AKBAR
ll t = 1;
cin>>t;
while(t--)
{
sir33();
}
return 0;
}