#include <iostream>

using namespace std;

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