#include<iostream>
#include<stack>
using namespace std;
stack<int>s;
int pushed[100005],poped[100005],no[100005];
int main(){
int q;
cin>>q;
for(int i = 0;i < q;++i){
int n,sfront = 0,f = 0;
cin>>n;
for(int j = 1;j <= n;++j) cin>>pushed[j],no[pushed[j]] = j;
for(int j = 1;j <= n;++j){
cin>>poped[j];
int u = no[poped[j]];
if(u > sfront) {
for(int k = sfront + 1;k <= u - 1;++k){
s.push(k);
}
sfront = u;
}
else {
if(!s.empty() && u == s.top()){
s.pop();
}
else{
cout<<"No"<<endl;
f = 1;
break;
}
}
}
if(!f) cout<<"Yes"<<endl;
while(!s.empty()) s.pop();
}
return 0;
}