#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];
        bool mark[MAXN]={false};
        long long br[MAXN]={0};
        for (long long i=1;i<=n;i++) cin>>a[i];
        for (long long i=1;i<=n;i++) cin>>b[i];
        for (long long i=1;i<=n;i++)
        {
            for (long long j=1;j<=n;j++)
            {
                if (abs(i-j)%2==0 and a[i]==b[j])
                {
                    br[i]++;
                    mark[j]=true;
                }
                else if (abs(i-j)%2==1 and a[i]+b[j]==0)
                {
                    br[i]++;
                    mark[j]=true;
                }
            }
        }
        bool da1=true;
        bool da2=true;
        for (long long i=1;i<=n;i++)
        {
            if (br[i]==0)
            {
                da1=false;
                break;
            }
        }
        for (long long i=1;i<=n;i++)
        {
            if (!mark[i])
            {
                da2=false;
                break;
            }
        }
        if (da1 and da2) cout<<"DA"<<endl;
        else cout<<"NE"<<endl;
    }
}