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

int main() 
{
  int t,n,q,provera=-1,brojacnula=0,brojackeceva=0,pb,pa,w=0,d=0;
  cin>>t;
  vector<int>a;
  vector<int>b;
  for(int i=0;i<t;i++)
    {
      cin>>n;
      for(int j=0;j<n;j++)
        {
          cin>>q;
          a.push_back(q);
          if(provera==q || provera==q*-1)
            brojacs++;
          provera=q;
          if(q==0)
            brojacnula++;
          else
            pa=j;
          if(q==1 || q==-1)
            brojackeceva++;
          
        for(int j=0;j<n;j++)
        {
          cin>>q;
          b.push_back(q);
          if(q!=0)
            pb=j;
        }
        }
      if(brojacnula==n-1)
      {if(pb%2==pa%2)
          cout<<"DA";
        else
          cout<<"NE";}
      else
      { for(int x:a)
          {
            for(int y:b)
              {
                if(x==y)
                  w++;
              }
          }
    }
      if(w==n)
        cout<<"DA";
          else
        cout<<"NE";
      }
  
    return 0;
}