#include <iostream>
#include <algorithm>
#include <queue>

int factorial(int n) {
    if (n == 0)
        return 1;
    
    return factorial(n - 1) * n;
}

int main() {
    int t;
    std::cin >> t;

    while (t--) {
        int n, a[100010], b[100010];
        std::cin >> n;

        for (int i = 0; i < n; ++i) std::cin >> a[i];
        for (int i = 0; i < n; ++i) std::cin >> b[i];

        for (int i = 0; i < n; ++i) {
            while (a[i] % 2 == 0)
                a[i] /= 2;
            
            while (b[i] % 2 == 0)
                b[i] /= 2;
        }

        std::sort(a, a + n);
        std::sort(b, b + n);

        int factN = factorial(n);

        bool areEqualAns = false;
        while (factN--) {
            bool areEqual = true;

            for (int i = 0; i < n; ++i) {
                int x, y;
                x = a[i]; y = b[i];

                while (x != y && x >= y) {
                    x /= 2;
                }
                if (x != y || x == 0)
                    areEqual = false;   
            }

            if (areEqual) {
                areEqualAns = true;
                break;
            }

            std::next_permutation(b, b + n);
        }

        std::cout << (areEqualAns ? "DA": "NE") << "\n";
    }
}