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
#include <bits/stdc++.h>

#pragma GCC optimize("O3", "unroll-loops")

using namespace std;

const int maxn = 5e4;
const int maxm = 4e5;
const int N = maxn/64+1;

using ll = unsigned long long;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    ll a[1+maxn+maxm][N] = {};
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < n; j += i) {
            a[i][j >> 6] |= 1 << (j & 63);
        }
    }
    int t, u, v;
    for (int i = n+1; i <= n+m; i++) {
        cin >> t;
        if (t == 1) {
            cin >> u >> v;
            for (int j = 0; j < N; j++) {
                a[i][j] = a[u][j] | a[v][j];
            }
        }
        if (t == 2) {
            cin >> u >> v;
            for (int j = 0; j < N; j++) {
                a[i][j] = a[u][j] & a[v][j];
            }
        }
        if (t == 3) {
            cin >> u;
            for (int j = 0; j < N; j++) {
                a[i][j] = ~a[u][j];
            }
        }
    }
    while (q--) {
        cin >> u >> v;
        if (a[u][v >> 6] & (1 << (v & 63))) {
            cout << "TAK\n";
        } else {
            cout << "NIE\n";
        }
    }
    return 0;
}