My wrong code:
#include <bits/stdc++.h>
using namespace std;
stack<int>s;
int psd[100005],ppd[100005],q,n,x;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>q;
for(int i=1;i<=q;i++){
cin>>n;
for(int j=1;j<=n;j++) cin>>psd[j];
for(int j=1;j<=n;j++) cin>>ppd[j];
x=1;
for(int j=1;j<=n;j++){
s.push(psd[j]);
while(!s.empty()&&s.top()==ppd[x]){
s.pop();
x++;
}
}
if(s.empty()) cout<<"YES\n";
else cout<<"NO\n";
while(!s.empty()) s.pop();
}
return 0;
}
HELP ME!!!