#include <bits/stdc++.h>

using namespace std;

#define ll long long
const ll INF=1e9,LINF=1e18,mxN=1e5;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define pb push_back
#define PRINTvec(x) { cerr<<#x<<"="; for(int i=0;i<sz(x);i++) cerr<<x[i]<<" "; cerr<<endl; }

void Solve(){
    int N; cin>>N;
    bool nula=false;
    vector<int> a(N+1),b(N+1);
    vector<int> svi;
    map<int,int> cntA;
    map<int,int> cntB;
    for(int i=1;i<=N;i++){
        cin>>a[i];
        nula|=(a[i]==0);
        svi.pb(abs(a[i]));
    }
    for(int i=1;i<=N;i++){
        cin>>b[i];
        nula|=(b[i]==0);
        svi.pb(abs(b[i]));
    }
    sort(all(svi));
    svi.resize(distance(svi.begin(),unique(all(svi))));
    for(int i=1;i<=N;i++){
        bool nega=(a[i]<0);
        bool negb=(b[i]<0);
        a[i]=distance(svi.begin(),lower_bound(all(svi),abs(a[i])));
        b[i]=distance(svi.begin(),lower_bound(all(svi),abs(b[i])));
        if(!nula){
            a[i]++; b[i]++;
        }
        a[i]=(nega ? -a[i] : a[i]);
        b[i]=(negb ? -b[i] : b[i]);
        cntA[a[i]]++;
        cntB[b[i]]++;
    }
    for(auto p:cntA){
        if(cntA[p.fi]+cntA[-p.fi]!=cntB[p.fi]+cntB[-p.fi]){
            cout<<"NE"<<endl;
            return;
        }
    }
    vector<vector<vector<int>>> cntAA(N+1,vector<vector<int>>(2,vector<int>(2,0)));
    vector<vector<vector<int>>> cntBB(N+1,vector<vector<int>>(2,vector<int>(2,0)));
    for(int i=1;i<=N;i++){
        bool znak=(a[i]>0);
        bool poz=i&1;
        cntAA[abs(a[i])][znak][poz]++;
        znak=(b[i]>0);
        poz=i&1;
        cntBB[abs(b[i])][znak][poz]++;
    }
    for(int i=1;i<=N;i++){
        if(a[i]==0) continue;
        bool znak=(a[i]>0);
        bool poz=i&1;
        int x=abs(a[i]);
        if(cntAA[x][znak][poz]+cntAA[x][znak^1][poz^1]!=cntBB[x][znak][poz]+cntBB[x][znak^1][poz^1]){
            cout<<"NE"<<endl;
            return;
        }
    }
    cout<<"DA"<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--){
        Solve();
    }
    return 0;
}