ML_Ravenclaw @ 2022-07-11 17:05:23
#include <bits/stdc++.h>
using namespace std;
int t;
int main()
{
cin>>t;
while(t--)
{
stack<long long>c;
long long n,a[100010]={0},b;
cin>>n;
for(int i = 1;i<=n;i++)
{
cin>>a[i];
}
int k=0;
bool f = 1;
for(int i = 1;i<=n;i++)
{
cin>>b;
if(c.top()==b)c.pop();
else
{
while(c.top()!=b&&k<=n)c.push(a[++k]);
if(c.top()!=b)
{
cout<<"No\n";
f=0;
break;
}
else c.pop();
}
}
if(f==1)cout<<"Yes\n";
}
return 0;
}