#include <iostream>
#include <algorithm>
using namespace std;

const int maks=30010;
void zamena(int a[],int b[],int n,int i, int j)
{
      swap(a[i],a[j]);
      a[i]*=-1;
      a[j]*=-1;
}
int main()
{
    int T,a[maks],b[maks],n,indeksA,indeksB,trazenA,trazenB;
    cin>>T;
    while(T>0)
    {
        cin>>n;
        for(int i=1;i<n+1;i++)cin>>a[i];
        for(int i=1;i<n+1;i++)cin>>b[i];
        for(int i=1;i<n+1;i++)
        {
            if(a[i]!=0)
            {
                trazenA=a[i];
                indeksA=i;
            }
            if(b[i]!=0)
            {
                trazenB=b[i];
                indeksB=i;
            }
        }
        if(abs(trazenA)==abs(trazenB))
        {
            if(abs(indeksA-indeksB)>1)
            {

                if(abs(indeksA-indeksB)%2==0)
                {
                   if(trazenA==trazenB)
                      cout<<"DA"<<endl;
                   else
                      cout<<"NE"<<endl;
                 }
                else
                {
                    if(trazenA!=trazenB)
                        cout<<"DA"<<endl;
                     else
                       cout<<"NE"<<endl;
               }
             }
             else
             {
                if(abs(indeksA-indeksB)==0)
                {
                    if(trazenA==trazenB)
                       cout<<"DA"<<endl;
                     else
                       cout<<"NE"<<endl;
                 }
                 else
                 {
                    if(trazenA==trazenB)
                       cout<<"NE"<<endl;
                    else
                        cout<<"DA"<<endl;
                 }
             }

        }
        else
            cout<<"NE"<<endl;
        T--;
    }

}