#include <bits/stdc++.h>
using namespace std;
int t, n, anot0, ani, bnot0, bni; int a[30096]; int b[30096];
void set1(int aa, int bb, int ai, int bi)
{
  if(aa == bb && !(abs(ai - bi) & 1))
    printf("DA\n");
  else if(aa == -bb && (abs(ai - bi) & 1))
    printf("DA\n");
  else printf("NE\n");
}
int main()
{
  scanf("%d", &t);
  while(t--)
  {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
      scanf("%d", &a[i]);
      if(a[i] != 0)
        anot0 = a[i], ani = i;
    }
    for(int i = 1; i <= n; i++)
    {
      scanf("%d", &b[i]);
      if(b[i] != 0)
        bnot0 = b[i], bni = i;
    }
    set1(anot0, bnot0, ani, bni);
  }

  return 0;
}