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

void solve(){
	ll n;
	cin>>n;
	vector <ll> a(n),b(n);
	bool f=false;
	
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];

	for(int i=1;i<n;i++){
		swap(a[i-1],a[i]);	
		a[i-1]=-a[i-1];
		a[i]=-a[i];
		for(int i=0,k=0;i<n;i++){
			if(a[i]==b[i]) k++;
			if(k==n-1){
				f=true;
				break;
			}
		}
		if(f) break;
 	}
 	if(f)cout<<"DA\n";
 	else cout<<"NE\n";
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	ll t;
	cin>>t;
	while(t--) solve();
	return 0;
}