#include<bits/stdc++.h>
using namespace std;
int main()
{
int q,n,a[100010],b[100010],pushed[100010],poped[100010],temp,p,qmax=0;
bool t=0;
cin>>q;
for(int i=1;i<=q;i++)
{
cin>>n;
for(int j=1;j<=n;j++)
{
cin>>pushed[j];
a[pushed[j]]=j;
}
for(int j=1;j<=n;j++)
{
cin>>poped[j];
b[poped[j]]=j;
}
for(int j=1;j<n;j++)
{
p=a[poped[j]],t=1;
for(int k=p-1;k>=1;k--)
{
if(b[a[k]]>j)
if(b[a[k]]>qmax) qmax=b[a[k]];
else {t=0;break;}
}
qmax=0;
if(!t) break;
}
if(t) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}