#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	for(int i2 = 0; i2 < t;i2++)
	{
		int n;
		cin >> n;
		int a[n],b[n];
		for(int j = 0; j < n;j++) cin >> a[j];
		for(int j = 0; j < n;j++) cin >> b[j];
		int loc1,loc2,x1,x2;
		for(int i = 0; i < n;i++)
		{
			if(a[i] != 0) {loc1 = i;x1 = a[i];}
			if(b[i] != 0) {loc2 = i;x2 = b[i];}
		}
			int raz = loc1 > loc2 ? loc1-loc2 : loc2-loc1;
			if(x1 != x2 && x1 != -x2)
			{
				cout << "NE";
			}
			else if(raz % 2 == 0)
			{
				if(x1 == x2)
				{
					cout << "DA";
				}
				else
				{
					cout << "NE";
				}
			}
			else
			{
				if(x1 == -x2)
				{
					cout << "DA";
				}
				else
				{
					cout << "NE";
				}
			}
			if(i2 != t-1) cout << "\n";
	}
}