#include <stdio.h>
#include <stdlib.h>

int main() {
    int T;
    int rez[1000];
    scanf("%d", &T);

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

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

        // check if A can be transformed to B
        int possible = 1;
        for (int j = 0; j < N; j++) {
            if (A[j] != B[j]) {
                int k = j + 1;
                while (k < N && A[k] != B[j]) {
                    k++;
                }
                if (k == N) {
                    possible = 0;
                    break;
                }
                while (k > j) {
                    int temp = A[k-1];
                    A[k-1] = A[k];
                    A[k] = temp;
                    A[k-1] *= -1;
                    k--;
                }
            }
        }

        // print the result
        if (possible) {
            rez[i]=0;
        } else {
            rez[i]=1;
        }
    }
    for(int i = 0; i < T; i++)
    {   if(rez[i]==0)
        {
                    printf("DA\n");
        }


        if(rez[i]==1)
        {

            printf("NE\n");
        }
    }

    return 0;
}