#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n+1],b[n+1];
        for(ll i=1;i<=n;i++)cin>>a[i];
        for(ll i=1;i<=n;i++)cin>>b[i];
        ll br1=0,br2=0;
        ll subtask1=0;
        for(ll i=1;i<=n;i++){
            br1+=(a[i]==0);
            br2+=(b[i]==0);
        }
        ll ok=0;
        map<ll,ll>os;
        for(ll i=1;i<=n;i++)os[a[i]]=1;
        for(ll i=1;i<=n;i++){
            ll r=0;
            r+=os[b[i]];
            r+=os[-b[i]];
            if(r==0)ok=1;
        }
        if(ok){
            cout<<"NE";
            cout<<endl;
            continue;
        }
        subtask1+=(br1==n-1&&br2==n-1);
        if(subtask1){
            set<ll>s;
            for(ll i=1;i<=n;i++){
                s.insert(a[i]);
                s.insert(b[i]);
            }
            s.erase(0);
            if(s.size()==1){
                map<ll,ll>m;
                for(ll i=1;i<=n;i++){
                    m[a[i]]=i;
                }
                for(ll i=1;i<=n;i++){
                    if(b[i]!=0){
                        ll r=abs(m[b[i]]-i);
                        if(r%2)ok=1;
                    }
                }
                if(ok)cout<<"NE";
                else cout<<"DA";
                cout<<endl;
                continue;
            }
            map<ll,ll>m;
            for(ll i=1;i<=n;i++){
                m[a[i]]=i;
            }
            for(ll i=1;i<=n;i++){
                if(b[i]!=0){
                    ll r=abs(m[-b[i]]-i);
                    if(r%2==0){
                        ok=1;
                    }
                }
            }
            if(ok)cout<<"NE";
            else cout<<"DA";
            cout<<endl;
            continue;
        }
        ll da=0;
        set<ll>provera1,provera2;
        for(int i=1;i<=n;i++){
            provera1.insert(a[i]);
            provera2.insert(b[i]);
        }
        if(provera1.size()==n&&provera2.size()==n)da=1;
        //cout<<provera1.size()<<" "<<provera2.size()<<endl;
        if(da){
            //cout<<1;
            map<ll,ll>m;
            for(ll i=1;i<=n;i++)m[a[i]]=i;
            for(ll i=1;i<=n;i++){
                if(m[b[i]]){
                    // isti znak
                    ll r=abs(i-m[b[i]]);
                    if(r%2)ok=1;
                }
                else {
                    // razlicit znak
                    ll r=abs(i-m[-b[i]]);
                    if(r%2==0)ok=1;
                }
            }
        }
        else {
            //cout<<2;
            for(int i=1;i<=n;i++){
                if(a[i]==b[i])continue;
                int o=0;
                int r;
                for(int j=i+2;j<=n;j+=2){
                    if(b[j]==a[i]){
                        r=j;
                        o=1;
                        break;
                    }
                }
                if(!o){
                    ok=1;
                    break;
                }
                for(int j=r;j>i;j--){
                    swap(a[j-1],a[j]);
                    a[j]=-a[j];
                    a[j-1]=-a[j-1];
                }
            }
        }
        if(ok)cout<<"NE";
        else cout<<"DA";
        cout<<endl;
    }
}