#include <iostream>
#include <stack>
#include <vector>
using namespace std;

bool judge(vector<int> & pushed,vector<int> & poped)
{
    stack<int> s;

    int m=pushed.size();
    int j=0;

    for(int i=0;i<m;i++)
    {
        s.push(pushed[i]);

        while(!s.empty()&&s.top()==poped[j])
        {
            s.pop();
            j++;
        }
    }

    return s.empty();
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int q;
    cin>>q;
    while(q--)
    {
        int n;
        cin>>n;

        vector<int> pushed(n);
        vector<int> poped(n);

        for(int i=0;i<n;i++) cin>>pushed[i];
        for(int j=0;j<n;j++) cin>>poped[j];

        if(judge(pushed,poped)) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}
// 64 位输出请用 printf("%lld")