#include <bits/stdc++.h>
using namespace std;
int t, n, anot0, ani, bnot0, bni; int a[30096]; int b[30096];
int st1;
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");
}
void set2()
{
  bool st2; int c;
  for(int i = 1; i <= n; i++)
  {
    if(a[i] == b[i])
      continue;
    if(a[i] != b[i] && (a[i+1] != a[i] && a[i-1] != a[i]) || (b[i+1] != b[i] && b[i-1] != b[i]))
    {
      printf("NE\n"); c = -15; break;
    }
    else if(a[i] != b[i] && (a[i-1] == a[i] || a[i+1] == a[i]) &&(b[i-1] == b[i] || b[i+1] == b[i]))
      c++;
  }
  if((c & 1) == 0 && c != -15)
    printf("DA\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, st1++;
    }
    for(int i = 1; i <= n; i++)
    {
      scanf("%d", &b[i]);
      if(b[i] != 0)
        bnot0 = b[i], bni = i, st1++;
    }
    if(st1 == 2)
    set1(anot0, bnot0, ani, bni);
    else set2();
  }

  return 0;
}