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

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

int t; cin >> t;
while (t--){
    ll n; cin >> n;
    ll a[300010], b[300010];
    ll poza = 0, pozb = 0;
    for( ll i = 0; i < n; i++ ){
        cin >> a[i];
        if ( a[i] != 0 ){
            poza = i;
        }
    }
    for ( ll j = 0; j < n; j++ ){
        cin >> b[j];
        if ( b[j] != 0 ){
            pozb = j;
        }
    }
    if ( a[poza] + b[pozb] == 0 ){
        if ( (poza - pozb)%2 == 0 ){
            cout << "NE" << endl;
        }
        else{
            cout << "DA" << endl;
        }
    }
    else{
        cout << "NE"<< endl;
    }
}

return 0;
}