#include <iostream>
using namespace std;
#include<stack>
#include<vector>
int main() {
int T;
cin>>T;
while(T--){
vector<int>vpush;
vector<int>vpop;
int n;
cin>>n;
for(int i=0;i<n;i++){
int a;
cin>>a;
vpush.push_back(a);
}
for(int i=0;i<n;i++){
int a;
cin>>a;
vpop.push_back(a);
}
//--------------------------双指针 ij
stack<int>s;
int i=0,j=0;
for( i=0;i<n;){
s.push(vpush[i]);
if(s.top()!=vpop[j]){
i++;
}
else if(s.top()==vpop[j]){
while(!s.empty()&&s.top()==vpop[j]){
s.pop();
j++;
}
i++;
}
}
if(s.empty()){
cout<<"Yes"<<endl;
}
else {
cout<<"No"<<endl;
}
}
}
// 64 位输出请用 printf("%lld")