#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long t = 0;
    long long n = 0;
    cin >> t;
    long long a[30001];
    long long b[30001];
    long long bra = 0;
    long long brb = 0;
    long long brojac_a = 0;
    long long brojac_b = 0;
    bool moze = true;
    bool moze1 = true;
    long long broj_a = 0;
    long long broj_b = 0;
    long long poz_a = 0;
    long long poz_b = 0;


    for (long long j = 0; j < t; j++)
    {
        cin >> n;
        for (long long i = 0; i < n; i++)
        {
            cin >> a[i];
            if (a[i] != 0)
            {
                brojac_a++;
                poz_a = i;
                bra = a[i];

            }
            if ((a[i] == 1 || a[i] == -1) && moze)
            {
                broj_a += a[i];
                moze = true;
            }
            else
            {
                moze = false;
            }

        }
        for (long long i = 0; i < n; i++)
        {
            cin >> b[i];
            if (b[i] != 0)
            {
                brojac_b++;
                poz_b = i;
                brb = b[i];

            }
            if ((b[i] == 1 || b[i] == -1) && moze)
            {
                broj_b += b[i];
                moze1 = true;
            }
            else
            {
                moze1 = false;
            }
        }

        if (brojac_a == 1 && brojac_b == 1 && abs(bra) == abs(brb))
        {
            if (bra * pow(-1, abs(poz_a - poz_b)) == brb)
            {
                cout << "DA" << endl;
            }
            else
            {
                cout << "NE" << endl;
            }
        }
        else if (moze && moze1)
        {
            if (abs(broj_a) == abs(broj_b))
            {
                cout << "DA" << endl;
            }
            else
            {
                cout << "NE" << endl;
            }
        }
    }


    return 0;
}