#include <bits/stdc++.h>
using namespace std;
int T, N, ia, ib, a, b; long long ai[30005], bi[30005]; bool resenje, par;
int main(){
cin >> T;
for(int i=1; i<=T; i++){
    cin >> N;
    for(int j=1; j<=N; j++){
        cin >> ai[j];
        if(ai[j]!=0){
            ia=j;
            a=ai[j];
        }

    }
    for(int j=1; j<=N; j++){
        cin >> bi[j];
        if(bi[j]!=0){
            ib=j;
            b=bi[j];
        }
    }
    cout<<a<<" "<<b<<endl;
    if(abs(a) == abs(b)){
        if(a == b and abs(ia - ib)%2 == 0 or a != b and abs(ia-ib)%2 == 1){
            resenje = false;
        }
    }
 if(resenje == false){
    cout<<"NE"<<endl;
 }else{
 cout<<"DA"<<endl;
 }

}
return 0;
}