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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	for(int i = 0; i < t;i++)
	{
		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];
		while(true)
		{
			int p = 0;
			for(int j = 0; j < n-1; j++)
			{
				int x1 = a[j],x2 = a[j+1];
				if(x1 != b[j] && x2 != b[j+1])
				{
					a[j] = -x2;a[j+1] = -x1;
					p++;
				}
			}
			int jed = 0;
			for(int i = 0; i < n;i++)
			{
				if(a[i] != b[i])
				{
					jed = 1;break;
				}
			}
			if(jed == 1 && p == 1)
			{
				cout << "NE";
				break;
			}
			else if(jed == 0 && p == 0)
			{
				cout << "DA";
				break;
			}
		}
	}
}