/*
*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;
}
void sir3()
{
ll n; cin>>n;
vector<ll>a(n),b(n);
for(auto &e:a) cin>>e;
for(auto &d:b) cin>>d;
rsrt(a); srt(b);
bool ok = true;
for(ll i=1; i<n-1; i++)
{
if(a[i]<b[i-1]|| a[i]<b[i+1]) ok = false;
}
if(ok)
{
yes; return;
}
srt(a); rsrt(b);
ok = true;
for(ll i=1; i<n-1; i++)
{
if(b[i]<a[i-1]|| b[i]<a[i+1]) ok = false;
}
if(ok)
{
yes; return;
}
no;
return;
}
int main() {
ALLAHU_AKBAR
ll t = 1;
cin>>t;
while(t--)
{
sir3();
}
return 0;
}