#include using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' //#define vec vector //#define mat vector > #define fi first #define se second #define double long double typedef long long ll; typedef unsigned long long ull; typedef pair pll; //typedef long double ld; typedef complex Complex; const ll INF=1e9+7; const ll MOD=998244353; const ll inf=INF*INF; const ll mod=MOD; const ll MAX=200010; const double PI=acos(-1.0); typedef vector > mat; typedef vector vec; void solve(){ ll t;cin>>t; while(t--){ ll n;cin>>n; vectora(n),b(n); vector >c(n); vectord(n); rep(i,n){ cin>>a[i]; a[i]--; c[a[i]].pb(i); } rep(i,n){ cin>>b[i]; b[i]--; d[i]=mp(b[i],i); } sort(all(d)); bool ans=1; setst,st2; queueq; rep(i,n){ ll k=d[i].se; if(b[k]a[k]){ auto itr=lower_bound(all(c[b[k]]),k); bool f=0; if(itr!=c[b[k]].end()){ ll s=*itr; auto itr2=st.lower_bound(k); if(itr2!=st.end()){ ll z=*itr2; if(z>s){ f=1; } }else{ f=1; } } if(itr!=c[b[k]].begin()){ itr--; ll s=*itr; auto itr2=st2.lower_bound(-k); if(itr2!=st2.end()){ ll z=-*itr2; if(zd[i].fi){ while(!q.empty()){ ll l=q.front(); q.pop(); st.insert(l); st2.insert(-l); } } } cout<<(ans?"Yes":"No")<