#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int n;
        cin>>n;
        long ai,bi,a[n],b[n];
        for(int j=0;j<n;j++){
            cin>>a[j];
            if(a[j]!=0)ai=j;
        }
        for(int j=0;j<n;j++){
            cin>>b[j];
            if(b[j]!=0)bi=j;
        }
        //cerr<<"a = "<<a[ai]<<", b = "<<b[bi]<<", ai, bi "<<ai<<" "<<bi<<endl;
        //cerr<<abs(ai-bi)<<endl;
        if(abs(a[ai])==abs(b[bi])){
            if(abs(ai-bi)%2==0 || abs(ai-bi)==0){
                //cerr<<1<<endl;
                if(a[ai]==b[bi])cout<<"DA"<<"\n";
                else cout<<"NE"<<"\n";
            }
            else{
                //cerr<<2<<endl;
                if(a[ai]!=b[bi])cout<<"DA"<<"\n";
                else cout<<"NE"<<"\n";
            }
        }
    }
    return 0;
}