#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(int argc, char** argv) {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin>>t;
	for (int i=0;i<t;i++){
		int n;
		cin>>n;
		int poz1,poz2,broj1,broj2;
		vector <int> a(n),b(n);
		for (int i=0;i<n;i++){
			cin>>a[i];
			if (a[i]!=0){
				poz1=i;
				broj1=a[i];
			}
		}
		for (int i=0;i<n;i++){
			cin>>b[i];
			if (b[i]!=0){
				poz2=i;
				broj2=b[i];
			}
		}
		if (((broj1>0) and (broj2>0)) or ((broj1<0) and (broj2<0))){
			if (abs(poz1-poz2)%2==1){
				cout<<"NE\n";
				continue;
			}
		}
		if (((broj1>0) and (broj2<0)) or ((broj1<0) and (broj2>0))){
			if (abs(poz1-poz2)%2==0){
				cout<<"NE\n";
				continue;
			}
		}
        if (abs(broj1)!=abs(broj2)){
            cout<<"NE\n";
            continue;
        }
		cout<<"DA\n";
	}
	
	return 0;
}