chris731 @ 2023-03-12 22:27:34
#include<bits/stdc++.h>
using namespace std;
stack<int>s;
int a[10000009];
int main(){
int q;
cin>>q;
for(int i=1;i<=q;i++){
while(s.empty()==0){
s.pop();
}
int n,lj=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
int o=1,w,oo=1;
for(int i=1;i<=n;i++){
if(lj>0){
break;
}
while(s.empty()==1 or a[i]!=s.top()){
if(o>n){
lj++;
cout<<lj<<" lj "<<"No"<<endl;
break;
}
if(oo<=n){
cin>>w;
}
//cout<<w<<" w ";
s.push(w);
//cout<<a[i]<<" a[i] "<<s.top()<<" s.top() "<<lj<<" lj ";
o++;
oo++;
if(a[i]==s.top()){
s.pop();
o--;
}
}
}
if(lj==0){
cout<<"Yes"<<endl;
}
}
return 0;
}