#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
vector<int>a;
vector<int>b;

int main()
{
    int t, n, ai, bi, bri, indm, k;
    cin >> t;
    for (int i = 0; i < t; i++) {
        cin >> n;
        for (int j = 0; j < n; j++) {
            cin >> ai;
            a.push_back(ai);
        }
        bri = 0;
        k = 1;
        bool d = true;
        indm = 0;
        for (int j1 = 0; j1 < n; j1++) {
            cin >> bi;
            if (!d) continue;
            b.push_back(bi);
            vector<int>::iterator mit, pit;
            if (bi < 0) mit = find(a.begin(), a.end(), bi);
            else mit = find(a.begin(), a.end(), bi * -1);
            pit = find(a.begin(), a.end(), abs(bi));
            if (mit != a.end()) {
                int ind = mit - a.begin();
                if (ind < indm) {
                    a[mit - a.begin()] *= k;
                    ind += bri;
                }
                if (abs(ind - j1) % 2 == 0) {
                    if (a[mit-a.begin()] != bi) {
                        d = false;
                    }
                    else {
                        indm = ind;
                        k *= -1;
                        bri++;
                    }
                }
                else {
                    if (a[mit - a.begin()] * -1 != bi) {
                        d = false;
                    }
                    else {
                        indm = ind;
                        k *= -1;
                        bri++;
                    }
                }
                a[mit - a.begin()] = 1000000001;
            }
            else if (pit != a.end()) {
                int ind = pit - a.begin();
                if (ind < indm) {
                    a[pit - a.begin()] *= k;
                    ind += bri;
                }
                if (abs(ind - j1) % 2 == 0) {
                    if (a[pit - a.begin()] != bi) {
                        d = false;
                    }
                    else {
                        indm = ind;
                        k *= -1;
                        bri++;
                    }
                }
                else {
                    if (a[pit-a.begin()] * -1 != bi) {
                        d = false;
                    }
                    else {
                        indm = ind;
                        k *= -1;
                        bri++;
                    }
                }
                a[pit - a.begin()] = 1000000001;

            }

        }
        if (d) cout << "DA" << endl;
        else cout << "NE";
    }
}