#include <iostream>

using namespace std;

int main()
{
    int t, n;
    int possible = 1;
    cin >> t;
	int pa[t];
    for(int k = 0; k < t; k++){
    	pa[k] = 1;
    	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];
		}
		for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) {
            if (i == n - 1 || a[i] != -b[i+1] || b[i] != -a[i+1]) {
                pa[k] = 0;
                break;
            }
                int tmp = a[i];
                a[i] = -a[i+1];
                a[i+1] = -tmp;
        }
    	}
	}
	for(int k = 0; k < t; k++){
		if(pa[k] == 1){
			cout << "DA" << endl;
		}
		else{
			cout << "NE" << endl;
		}
	}
    return 0;
}