#include<bits/stdc++.h>
using namespace std;
void judge(stack<int> pushedt,stack<int> poped){
while(!pushedt.empty( )&&!poped.empty( )){
if(pushedt.top( )!=poped.top( )){
cout<<"No"<<endl;
return;
}
pushedt.pop( );
poped.pop( );
}
cout<<"Yes"<<endl;
}
int main( ){
int Q;cin>>Q;
while(Q--){
stack<int> pushed;
stack<int> poped;
stack<int> pushedt;
int n;cin>>n;
for(int i=0;i<n;i++){
int j;cin>>j;
pushed.push(j);
}
for(int i=0;i<n;i++){
int j;cin>>j;
poped.push(j);
}
while(!pushed.empty( )){
pushedt.push(pushed.top( ));
pushed.pop( );
}
judge(pushedt,poped);
}
return 0;
}