1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q;
    cin >> n >> m >> q;

    bitset<50001> A[n + m + 1];
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (j % i == 0) {
                A[i].set(j);
            }
        }
    }

    int operation, x, y;
    for (int i = 1; i <= m; i++) {
        cin >> operation;
        if (operation == 3) {
            cin >> x;
            A[n + i] = ~A[x];
        }
        else if (operation == 2) {
            cin >> x >> y;
            A[n + i] = A[x] & A[y];
        }
        else {
            cin >> x >> y;
            A[n + i] = A[x] | A[y];
        }
    }

    int v;
    bool res[q + 1];
    for (int i = 1; i <= q; i++) {
        cin >> x >> v;
        res[i] = A[x][v];
    }

    for (int i = 1; i <= q; i++) {
        if (res[i]) {
            cout << "TAK\n";
        }
        else {
            cout << "NIE\n";
        }
    }

    return 0;
}