k = int(input())
l = []
e = 0
for i in range(0,k):
  a=int(input())
  x=list(map(int,input().split()))
  y=list(map(int,input().split()))
  for i in range(0,a-1):
    e = x[i]
    x[i]=x[i+1]*-1
    x[i+1]=e*-1
  if a>2:
    x = sorted(x)
  y = sorted(y)

  if(x==y):
    print("DA")
  else:
    print("NE")