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


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

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

    }
    bool ok=true;
    for(int i=0;i<n;++i)
    {
        if(b[i]!=0) {
        for(int j=0;j<n;++j)
        {
            if(b[i] == a[j])
            {
                if(i-j%2==1)
                    ok = false;
            }
        }
        }
    }
    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();
    }







}