#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t,n,c,k2;
    bool provera = true;
    cin >> t;
    int o[t] ;
    for (int r = 0; r < t; r++)
    {
        cin>>n;
        int a[n], b[n];
        for(int i = 0; i < n; i++)
        {
            cin>>a[i];
        }
        for(int i = 0; i < n; i++)
        {
            cin>>b[i];
        }
        for(int i = 0; i < n && provera == true; i++)
        {
            for (int k = i; k < n && provera == true; k++)
            {
                if(abs(a[k]) == abs(b[i]))
                {
                    k2 = k;
                    while (k2 != i)
                    {
                        c = -a[k2-1];
                        a[k2-1] = -a[k2];
                        a[k2] = c;
                        k2 -= 1;
                    }
                    if(a[i] != b[i])
                    {
                        o[r] = 0;
                        provera = false;
                    }
                }
            }
        }
        if (provera == false)
        {
            provera = true;
        }
        else{
            o[r] = 1;
        }
    }
    for(int i = 0; i < t; i++)
    {
        if (o[i])
        {
            cout << "DA" << endl;
        }
        else {
            cout << "NE" << endl;
        }
    }
    return 0;
}