#include<iostream>
#include<stack>
#include<vector>
using namespace std;
bool jc(const int& n,const vector<int>& poshed,const vector<int>& popped)//只读引用就行
{
    stack<int> st;//模拟栈
    int j=0;//追踪popped
    for(int i=0;i<n;i++)
    {
       st.push(poshed[i]);
       while(!st.empty()&&st.top()==popped[j])//注意先判断再读取,并用顺序不能错
       {
        st.pop();//匹配成功
        j++;//指针后移
       }
    }
    return st.empty();//为空则合法
}
int main()
{
    int t;cin>>t;
    while(t--)
    {
        int n;cin>>n;
        vector<int> poshed(n);
        vector<int> popped(n);
        for(int i=0;i<n;i++)cin>>poshed[i];
        for(int i=0;i<n;i++)cin>>popped[i];
        if(jc(n,poshed,popped))cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}