#include <stdio.h>
#include <stdbool.h>

bool can_transform(int A[], int B[], int n) {
    int i, j;
    bool transformable = true;

    for (i = 0; i < n; i++) {
        if (A[i] != B[i]) {
            for (j = i + 1; j < n; j++) {
                if (A[j] == B[i]) {
                    while (j > i) {
                        int temp = A[j];
                        A[j] = A[j-1];
                        A[j-1] = temp;
                        A[j] *= -1;
                        j--;
                    }
                    break;
                }
            }
            if (j == n) {
                transformable = false;
                break;
            }
        }
    }

    return transformable;
}

int main() {
    int T;
    scanf("%d", &T);

    int i, j;
    for (i = 0; i < T; i++) {
        int n;
        scanf("%d", &n);

        int A[n], B[n];
        for (j = 0; j < n; j++) {
            scanf("%d", &A[j]);
        }
        for (j = 0; j < n; j++) {
            scanf("%d", &B[j]);
        }

        if (can_transform(A, B, n)) {
            printf("DA\n");
        } else {
            printf("NE\n");
        }
    }

    return 0;
}