_hello_w_ @ 2021-12-24 20:17:24
# include <bits/stdc++.h>
using namespace std;
int q,n,pushed[100005],poped[100005];
stack<int> a;
int main()
{
cin>>q;
for (int i = 0; i < q; i++)
{
cin>>n;
for (int j = 0; j < n; j++) cin>>pushed[j];
for (int j = 0; j < n; j++) cin>>poped[j];
int t = 0;
for (int j = 0; j < n; j++)
{
a.push(pushed[j]);
while (!a.empty() && a.top() == poped[t])
{
a.pop();t++;
}
}
if (a.empty()) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
while (!a.empty()) a.pop();
}
return 0;
}