#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
    int t;
    cin >> t;
    string sol[t];
    for(int m = 0; m < t; m++){
    int n;
    cin >> n;
    int a[n], b[n];
    int ai, bi, ak, bk;
    for(int i = 0; i <n; i++)
    {
        cin >> a[i];
        if(a[i] != 0)
        {
            ai = i;
            ak = a[i];
        }
    }
    for(int i = 0; i <n; i++)
    {
        cin >> b[i];
        if(b[i] != 0)
        {
            bi = i;
            bk = b[i];
        }
    }
    if(ai - bi %2 == 0 && ak == bk || ai - bi %2 == 1 && ak == -bk)
    {
        sol[m] = "DA";
    }
    else{
        sol[m] = "NE";
    }
    }
    for(int i = 0 ; i < t;i++)
    {
        cout << sol[i] << endl;
    }
    return 0;
}