#include<bits/stdc++.h>
using namespace std;
int main(){
	#define int long long
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		vector<int> a(n);
		vector<int> b(n);
		for(int i=0;i<n;i++) cin>>a[i];
		for(int i=0;i<n;i++) cin>>b[i];
		bool st1 = false;
		int q,w;
		q = 0;
		w = 0;
		for(int i=0;i<n;i++){
			if(a[i]!=0) q++;
			if(b[i]!=0) w++;
		}
		if(q==1 && w==1) st1 = true;
		if(st1){
			int x,y, poz1, poz2;
			for(int i=0;i<n;i++){
				if(a[i]!=0){
					x = a[i];
					poz1 = i;
					}
				if(b[i]!=0){
					y = b[i];
					poz2 = i;
				}
			}
			if(abs(poz1-poz2)%2==0 && x==y) cout<<"DA"<<endl;
			else if(abs(poz1-poz2)%2==1 && x==-y) cout<<"DA"<<endl;
			else cout<<"NE"<<endl;
			continue;
		}
		map<int, int> poza;
		map<int, int> pozb;
		map<int, int> cnta;
		map<int, int> cntb;
		map<int, int> znakb;
		for(int i=0;i<n;i++){
			poza[abs(a[i])] = i;
			pozb[abs(b[i])] = i;
			cnta[a[i]]++;
			cntb[b[i]]++;
			if(b[i]==0) znakb[b[i]] = 0;
			else{
				znakb[abs(b[i])] = b[i]/abs(b[i]);
		}
		}
		int moze = true;
		map<int, int> dist;
		for(int i=0;i<n;i++){
			if(cnta[a[i]]+cnta[-a[i]] != cntb[a[i]]+cntb[-a[i]]) moze =  false;
		}
		if(!moze){
			cout<<"NE"<<endl;
			continue;
		}
		for(int i=0;i<n;i++){
			dist[a[i]] = abs(pozb[abs(a[i])]-i);
			if(dist[a[i]]%2==0 && znakb[abs(a[i])]==-1 && a[i]>0) moze = false;
			if(dist[a[i]]%2==0 && znakb[abs(a[i])]==1 && a[i]<0) moze = false; 
			if(dist[a[i]]%2==1 && znakb[abs(a[i])]==1 && a[i]>0) moze = false;
			if(dist[a[i]]%2==1 && znakb[abs(a[i])]==-1 && a[i]<0) moze = false;
		}
	//	cout<<dist[2]<<endl;
		if(!moze){
			cout<<"NE"<<endl;
			continue;
		}
		cout<<"DA"<<endl;
	}
}