#include <bits/stdc++.h>
using namespace std;
int q,n;
int a[1000000],b[1000000];
stack<int>s;
int main(){
cin>>q;
while(q--){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
int top=1;
for(int i=1;i<=n;i++){
s.push(a[i]);
while(s.top()==b[top]){
s.pop();
top++;
if(s.empty()){
break;
}
}
}
if(s.empty()){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
}