#include <bits/stdc++.h>

using namespace std;

#define MAXN 30010

int main()
{
    long long t;
    cin>>t;
    for (long long z=0;z<t;z++)
    {
        long long n;
        cin>>n;
        long long a[MAXN];
        long long b[MAXN];
        for (long long i=1;i<=n;i++) cin>>a[i];
        for (long long i=1;i<=n;i++) cin>>b[i];
        long long br=0;
        for (long long i=1;i<=n;i++)
        {
            if (a[i]!=0) br++;
        }
        if (br==1)
        {
            long long brr=0;
            for (long long i=1;i<=n;i++)
            {
                if (b[i]!=0) brr++;
            }
            if (brr!=br) cout<<"NE"<<endl;
            else
            {
                long long x,y;
                for (long long i=1;i<=n;i++)
                {
                    if (a[i]!=0) x=i;
                }
                for (long long i=1;i<=n;i++)
                {
                    if (b[i]!=0) y=i;
                }
                if (a[x]+b[y]==0 and abs(x-y)%2==1) cout<<"DA"<<endl;
                else if (a[x]==b[y] and abs(x-y)%2==0) cout<<"DA"<<endl;
                else cout<<"NE"<<endl;
            }
        }
    }
}