(高超力)
#include<bits/stdc++.h>
using namespace std;
stack<int>ans;
queue<int>s;
int pushed[100010],popped[100010],m,xb=1,tmp,n;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
xb=1;
memset(pushed,0,sizeof(pushed));
memset(popped,0,sizeof(popped));
while(!ans.empty())
ans.pop();
while(!s.empty())
s.pop();
cin>>m;
for(int j=1;j<=m;j++){cin>>tmp;s.push(tmp);}
for(int j=1;j<=m;j++){cin>>popped[j];}
for(int j=1;j<=m;j++){
ans.push(s.front());
s.pop();
if(ans.top()==popped[xb]){
while(ans.top()==popped[xb]){
xb++;
ans.pop();
if(ans.empty())break;
}
}
}
xb--;
if(xb!=m) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
}