#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))

using namespace std;

const ll LINF = 4e18;
const int mxN = 1e6+10, INF = 2e9;
ll n, m, a[mxN], b[mxN];

void Solve(){

    cin >> n;
    map<int, int> mp;
    set<int> s;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        if (a[i]) s.insert(abs(a[i]));
    }
    for (int i = 0; i < n; i++){
        cin >> b[i];
        if (b[i]) s.insert(abs(b[i]));
    }
    m = 1;
    for (int x : s)
        mp[x] = m++;
    for (int i = 0; i < n; i++){
        a[i] = (a[i] < 0 ? -1 : 1) * mp[abs(a[i])];
        b[i] = (b[i] < 0 ? -1 : 1) * mp[abs(b[i])];
    }
    vector<vector<int> > cnt(2, vector<int>(m, 0));
    for (int i = 0; i < n; i++){
        int t = i&1;
        if (a[i] < 0) t ^= 1;
        cnt[t][abs(a[i])]++;
        t = i&1;
        if (b[i] < 0) t ^= 1;
        cnt[t][abs(b[i])]--;
    }
    bool f = 1;
    for (int i = 1; i < m; i++)
        if (cnt[0][i] || cnt[1][i])
            f = 0;
    if (f) cout << "DA\n";
    else cout << "NE\n";
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;
    cerr << "Started!" << endl;

    int t = 1;
    cin >> t;
    while (t--)
        Solve();

    return 0;
}