#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

bool cmp(ll a[1000], ll b[1000], ll n)
{
    bool flag = true;
    for(int i=0;i<n;++i)
    {
        if(a[i] != b[i])
        {
            flag = false;
            break;
        }
    }
    return flag;
}

void dbg(ll a[1000], ll n)
{
    for(int i=0;i<n;++i)
    {
        cout << a[i] << " ";
    }
    cout << "\n";

}
void solve()
{
    ll n, cn1=0, cn2=0;
    ll e;
    bool all=true;
    cin >> n;
    ll a[n], b[n];
    for(int i=0;i<n;++i)
    {
        cin >> a[i];
        if(a[i] != 1 && a[i] != -1)
           all=false;
        if(a[i] < 0)
            cn1++;
    }
    for(int i=0;i<n;++i)
    {
        cin >> b[i];
        if(b[i] != 1 && b[i] != -1)
           all=false;
        if(b[i]<0)
            cn2++;
    }
    bool ok=true;
    bool flag;
    if(cmp(a, b, n))
    {
        cout << "DA";
    }
    else if(all)
    {
        if((cn1 % 2 == 0 && cn2 % 2 == 0) || (cn1 % 2 == 1 && cn2 % 2 == 1))
        {
            cout << "DA" << "\n";
        }
        else
        {
            cout << "NE" << "\n";
        }
    }
    else {
    for(int i=0;i<n;++i)
    {
        e=0;
        flag = false;
        for(int j=i;j<n;++j)
        {
            if(abs(a[i]) != abs(b[j]))
            {
                e++;
                //cout << e << "\n";
                flag = false;
            }
            else
            {
                if((a[i] != b[j] && e%2==1) || (a[i] == b[j] && e%2==0))
                {
                    flag = true;
                    for(int k=j;k>i;--k)
                    {
                        swap(b[k], b[k-1]);
                        b[k] *= -1;
                        b[k-1] *= -1;
                    }
                    continue;
                }
                e++;
            }
        }
        if(!flag)
        {
            ok = false;
            break;
        }
        //dbg(b, n);
    }
    ok? cout << "DA" << "\n" : cout << "NE" << "\n";
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);


    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }







}