#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define ff(i,a,b) for(int (i) = (a);(i)<(b);(i)++)
#define fff(i,a,b) for(int (i) = (a);(i)<=(b);(i)++)

using namespace std;
using namespace __gnu_pbds;

int main()
{
    FAST;
    int x, y,in,jn;
    int t;
    cin>>t;
    ff(i,0,t){
        int n;
        cin>>n;
        int A[n+5];
        int B[n+5];
        fff(j,1,n){
            cin>>A[j];
        }
        fff(j,1,n){
            cin>>B[j];
        }
        //count zeros
        int count0A = 0;
        int count0B = 0;
        fff(j,1,n){
            if(A[j] == 0){
                count0A++;
            }
            if(B[j] == 0){
                count0B++;
            }
        }
        if((count0A == N-1) && (count0B == N-1)){
            fff(j,1,n){
                if(A[j]!=0){
                    x= A[j];
                    in = j;
                }
            }
            ff(j,1,n){
                if(B[j]!=0){
                    y= B[j];
                    jn = j;
                }
            }
            if((y== -x && abs(in-jn)%2 == 1)|| (y == x && abs(in-jn)%2 == 0)){
                cout<<"DA"<<endl;
            }else{
                cout<<"NE"<<endl;
            }
        }else{
            fff(j,1,n){
                if(A[j]!= B[j]){
                    if(A[j] == A[j+1] &&B[j] == B[j+1]){
                        j++;
                    }else{
                        cout<<"NE"<<endl;
                        br = true;
                        break;
                    }
                }
            }
            if(br){
                br = false;
                continue;
            }
            cout<<"DA"<<endl;
        }
    }
    return 0;
}