#include <iostream>
#include <stack>
using namespace std;
int main() {
int q,n;
cin>>q;
for(int i=0;i<q; ++i){
int a[100010],p=1,x;
stack <int> b;
cin>>n;
for(int j=0;j<n;++j) cin>>a[j];
b.push(a[0]);
for(int j=0;j<n;++j){
cin>>x;
if((!b.empty())&&b.top()==x) b.pop();
else{
while(a[p]!=x) b.push(a[p++]);
p++;
}
}
if(b.empty()) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
第一个测试点过了,但是其他的都是RE,求大佬指点