#include <bits/stdc++.h>
using namespace std;
int p[199999],o[199999];
int main()
{
int q,n;
cin>>q;
stack<int> z;
for(int i=1;i<=q;i++)
{
cin>>n;
for(int j=1;j<=n;j++)
{
cin>>p[j];
}
for(int j=1;j<=n;j++)
{
cin>>o[j];
}
bool m[1999999]={};
int k=0;
bool flag=true;
for(int j=1;j<=n;j++)
{
int t=o[j];
if(m[t]==true)
{
if(t==z.top())
{
m[t]=false;
z.pop();
}
else
{
flag==false;
break;
}
}
else
{
while(m[t]==false)
{
k++;
int l=p[k];
z.push(l);
m[l]=true;
}
m[t]=false;
z.pop();
}
}
if(flag==true)
{
cout<<"Yes";
}
else
{
cout<<"No";
}
cout<<endl;
}
return 0;
}