#include <iostream>

using namespace std;

void Zamena(int *a, int *b)
{
    int pom = *a;
    *a = *b;
    *b = pom;

    *a = -*a;
    *b = -*b;
}

int main()
{

   int t;
   int odg[100];
   cin >> t;

    int a[40000];
    int b[40000];

   for (int i = 0; i < t; i++)
   {

       int indikator = 0;

       int n;

       cin >> n;

       int n1 = n;


     for (int i = 0; i < n; i++)
     {
         cin >> a[i];
     }
     for (int i = 0; i < n; i++)
     {
         cin >> b[i];
     }

     int br = 0;

    for (int i = 0; i < 100; i++)
    {
        indikator = 0;

        for (int i = 0; i < n1 - 1; i++)
        {
          Zamena(&b[i], &b[i + 1]);
        }

        for (int i = 0; i < n; i++)
        {
           if (a[i] != b[i])
           {
               indikator = 1;
           }
        }


        n1--;

        if (n1 == 1)
            break;

        if (indikator == 0)
            break;

    }


       for (int i = 0; i < n; i++)
        {
          if (a[i] != b[i])
            indikator = 1;
        }



     odg[i] = indikator;

   }

    for (int i = 0; i < t; i++)
    {
        if (odg[i] == 1)
            cout << "NE" << endl;
        else if (odg[i] == 0)
            cout << "DA" << endl;

    }

    return 0;
}