#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%i",&t);
    while(t--)
    {
        int n;
        scanf("%i",&n);
        int a[n+1],b[n+1];
        map<int,int>mapa1;
        map<int,int>mapa2;
        bool bul=true;
        for(int i=1;i<=n;i++)
        {
            scanf("%i",&a[i]);
            //if(a[i]==0) continue;
            mapa1[abs(a[i])]++;
            if(abs(a[i])!=1) bul=false;
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%i",&b[i]);
            //if(a[i]==0) continue;
            mapa2[abs(b[i])]++;
            if(abs(b[i])!=1) bul=false;
        }
        int res=1;
        if(bul)
        {
            int ct1=0,ct2=0;
            for(int i=1;i<=n;i++)
            {
                if(a[i]==-1) ct1++;
                if(b[i]==-1) ct2++;
            }
            if(abs(ct1-ct2)%2==1)
            {
                res=0;
                printf("NE\n");
                continue;
            }
            int u=0,v=0;
            ct1=0,ct2=0;
            for(int i=1;i<=n;i++)
            {
                if(a[i]==1) ct1++;
                else
                {
                    u+=ct1;
                }
                if(b[i]==1) ct2++;
                else
                {
                    v+=ct2;
                }
            }
            if(abs(u-v)%2==1)
            {
                printf("NE\n");
                continue;
            }
            printf("DA\n");
            continue;
        }
        for(int i=1;i<=n;i++)
        {
            //if(a[i]==0) continue;
            if(mapa1[abs(a[i])]!=mapa2[abs(a[i])])
            {
                res=0;
            }
            //if(a[i]<0) mapa1[abs(a[i])]--;
            //if(b[i]<0) mapa1[abs(b[i])]--;
        }
        /*for(int i=1;i<=n;i++)
        {
            if((mapa1[abs(a[i])]-mapa2[abs(b[i])])%2==1)
            {
                res=0;
            }
        }*/
        if(res==0)
        {
            printf("NE\n");
            continue;
        }
        map<int,int>mapa3;
        map<int,int>mapa4;
        for(int i=1;i<=n;i++)
        {
            //if(a[i]==0) continue;
            mapa3[abs(a[i])]=i;
            mapa4[abs(b[i])]=i;
        }
        for(int i=1;i<=n;i++)
        {
            if(a[i]==0) continue;
            int temp=(abs(mapa3[abs(a[i])]-mapa4[abs(a[i])]))%2;
            if(temp==1 && a[i]==b[mapa4[abs(a[i])]])
            {
                res=0;
            }
            if(temp==0 && a[i]!=b[mapa4[abs(a[i])]])
            {
                res=0;
            }
        }
        if(res==0)
        {
            printf("NE\n");
            continue;
        }
        printf("DA\n");
    }
    return 0;
}