#include<bits/stdc++.h>
using namespace std;
int temp,q,n,k{1},p{0};vector<int>push,pop;stack<int>test;
int main(){
    cin>>q;
    for (int i=1; i<=q;++i) {
        cin>>n;k=1;p=0;push.clear();pop.clear();stack<int>().swap(test);
        for (int j=0; j<n;++j) {
            cin>>temp;push.push_back(temp);
        }
        for (int j=0; j<n;++j) {
            cin>>temp;pop.push_back(temp);
        }
        test.push(push[0]);
        while (!(test.empty())) {
            if (test.empty()||(k>=n&&(test.top()!=pop[p]))) {
                break;
            }
            while (!(test.empty())&&(test.top()==pop[p])) {
                test.pop();++p;
            }
            if (k<n) {
                test.push(push[k]);++k;
            }
        }
        if (test.empty()) {
            cout<<"Yes"<<endl;
        }else {
            cout<<"No"<<endl;
        }
    }
    return 0;
}