#include <bits/stdc++.h>
#define ll long long
#define yes cout << "DA\n"
#define no cout << "NE\n"
using namespace std;
bool check1(ll n,vector<ll>a,vector<ll>b) {
    ll x=0,y=0;
    for(ll i=0;i<n;i++) {
        if(a[i]!=0) x++;
        if(b[i]!=0) y++;
    }
    return (x==1&&y==1);
}
bool check2(ll n,vector<ll>a,vector<ll>b) {
    ll x=0,y=0;
    for(ll i=0;i<n;i++) {
        if(abs(a[i])==1) x++;
        if(abs(b[i])==1) y++;
    }
    return (x==n&&y==n);
}
void subtask2(ll n,vector<ll>a,vector<ll>b) {
    ll x=0,y=0;
    for(ll i=0;i<n;i++) {
        if(a[i]<0) x++;
        if(b[i]<0) y++;
    }
    if(x%2==y%2) {
        if(x%2==0) yes;
        else {
            ll p=1;
            for(ll i=1;i<n-1;i++) {
                if(a[i]==-1&&a[i-1]==1&&a[i+1]==1) p=1;
            }
            if(p) no;
            else yes;
        }
    }
    else no;
}
void subtask1(ll n,vector<ll>a,vector<ll>b) {
    ll x=0,y=0;
    for(ll i=0;i<n;i++) {
        if(a[i]!=0) x=i;
        if(b[i]!=0) y=i;
    }
    if(abs(a[x])!=abs(b[y])) {
        no;
        return;
    }
    if(b[y]<0) {
        if(a[x]>0) {
            if(abs(x-y)&1) yes;
            else no;
        }
        else {
            if(abs(x-y)%2==0) yes;
            else no;
        }
    }
    else {
        if(a[x]<0) {
            if(abs(x-y)&1) yes;
            else no;
        }
        else {
            if((abs(x-y)%2==0)) yes;
            else no;
        }
    }
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin >> t;
    while(t--) {
        ll n;
        cin >> n;
        vector<ll>a(n),b(n);
        for(ll i=0;i<n;i++) cin >> a[i];
        for(ll i=0;i<n;i++) cin >> b[i];
        if(check1(n,a,b)) {
            subtask1(n,a,b);
            continue;
        }
        if(check2(n,a,b)) {
            subtask2(n,a,b);
            continue;
        }
    }
    return 0;
}