#include <iostream>
#include<stack>
#include<vector>
using namespace std;
int main() {
int n;
cin>>n;
for(int i=1;i<=n;i++)//每一组
{
int length=0;
cin>>length;
stack<int> arr;
int outnum[length];
int innum[length];
int in=0,out=0;
bool judge=true;
for(int j=0;j<length;j++)//记录入栈顺序
{
cin>>innum[j];
}
for(int j=0;j<length;j++)//记录出栈顺序
{
cin>>outnum[j];
}
while(out<length)
{
if(!arr.empty()&&arr.top()==outnum[out])//栈顶元素等于出栈元素
{
arr.pop();
out++;
}
else if(in<length)
{
arr.push(innum[in]);
in++;
}
else{
judge=false;
break;
}
}
if(judge==false) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
}
}
// 64 位输出请用 printf("%lld")
记得回来重做

京公网安备 11010502036488号