#include <bits/stdc++.h>
#define ubrzaj ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)


using namespace std;

int main()
{
    ubrzaj;

    int t;
    cin >> t;
    for(int T=0; T<t; T++){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    int proizvod1=1,proizvod2=1;
    for(int i=0; i<n; i++){cin >> a[i];proizvod1*=a[i];}
    for(int i=0; i<n; i++){cin >> b[i];proizvod2*=b[i];}
    int res1=0,res2=0,poz1=0,poz2=0;
    int brnula1=count(a.begin(),a.end(),0);
    int brnula2=count(b.begin(),b.end(),0);

    if(proizvod1!=proizvod2) cout << "NE" << endl;
/*
    else if(brnula1==n-1 && brnula2==n-1){
    for(int i=0; i<n; i++){
        if(a[i]!=0){res1=a[i];poz1=i;}
        if(b[i]!=0){res2=b[i];poz2=i;}
    }
    if(n>2 && abs(res1)==abs(res2))cout << "DA" << endl;
    else if(n==2 and ((poz1==poz2 and res1==res2) or (poz1!=poz2 and res1==(-1*res2) ) ) )cout << "DA" << endl;
    else if(n==1 and poz1==poz2 and res1==res2)cout << "DA" << endl;
    else cout << "NE" << endl;
    }
    else {*/
        vector<int> c(n);
        for(int i=n-1; i>=0; i--)c[n-i-1]=(b[i]*(-1));
        bool OK=true;
        for(int i=0; i<n; i++)if(a[i]!=c[i])OK=false;
        if(OK==true)cout << "DA" << endl;
        else {
                int prosao=0;
            for(int i=0; i<n; i++){
                for(int j=0; j<n; j++){
                    /*if(a[i]==(-1)*b[j]){
                        b[i]=(-1)*a[i];
                    OK=true;
                    i++;
                    j++;
                    }
                    else if(a[i]==b[j] and i)*/
                    if(a[i]==b[i] and i==j){OK=true; break;}
                    else if(abs(a[i])==abs(b[j]) and abs(i-j)>1){
                        a[i]=b[j]=1000000001;
        prosao++;
                        /*i++;
                        j=0;*/
                    OK=true;
                    //cout << "OK " << i << ":" << j << endl;
                    break;
                    }
                    else {
                        OK=false;
                    //cout << "nijeOK " << i << ":" << j << endl;
                    }
                }

            }
            if(OK==true and prosao==n)
            cout << "DA" << endl;
            else cout << "NE" << endl;
        }

    //}


    }
    return 0;
}