badcow @ 2022-12-10 12:56:29
#include<bits/stdc++.h>
#define ll long long
#define pf printf
#define sf scanf
using namespace std;
stack<int>pu,po;
int ku[100010],ko[100010];
int main(){
int t,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=0;i<n;i++)scanf("%d",&ku[i]);
for(int i=0;i<n;i++)scanf("%d",&ko[i]);
for(int i=0;i<n;i++){
pu.push(ku[i]);
int f=1;
while(f==1){
if(pu.top()==ko[i]&&pu.empty()==false){
po.push(pu.top());
pu.pop();
}else{
f=0;
}
}
}
int l=0;
for(int i=n-1;i>=0;i--){
if(po.top()!=ko[i])l=1;
}
if(l==0)printf("Yes\n");
else printf("No\n");
}
return 0;
}//
蒟蒻求助111