#include <iostream>
#include <cmath>

using namespace std;

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL)

void ispis(int t1[100],int t){
	int i;
	
	for(i=0;i<t;i++){
		if(t1[i]==1)
			cout << "DA" << endl;
			
		else if(t1[i]==0)
			cout << "NE" << endl;
	}
}

int main(){
	int t,n,i,j,t1[100],b1=0,c=0,ind1,ind2;
	long int a[30000],b[30000];
	
	cin >> t;
	
	for(j=0;j<t;j++){
		cin >> n;
		
		for(i=0;i<n;i++){
			cin >> a[i];
		
			if(a[i]==0)
			c++;
			
			else
				ind1=i;
		}
		
		for(i=0;i<n;i++){
			cin >> b[i];
			if(b[i]==0)
			b1++;
			else
				ind2=i;
		}
		
		if(c==b1 && c==n-1){
			if(a[ind1]==b[ind2] && abs(ind1-ind2)%2==0)
				t1[j]=1;
					
			else if(a[ind1]==(b[ind2]*(-1)) && abs(ind1-ind2)%2==1)
				t1[j]=1;
				
			else
				t1[j]=0;
		}
			
		
	}
	
	ispis(t1,t);
	return 0;
}