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

using namespace std;

const int MAXN = 50001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, q;
    cin >> n >> m >> q;
    vector<bitset<MAXN>> sets(n + m + 1);
    bitset<MAXN> univ;
    for (int j = 1; j <= n; j++) univ[j] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            sets[i][j] = 1;
        }
    }
    for (int i = 1; i <= m; i++) {
        int tp;
        cin >> tp;
        if (tp == 1) {
            int x, y;
            cin >> x >> y;
            sets[n + i] = sets[x] | sets[y];
        } else if (tp == 2) {
            int x, y;
            cin >> x >> y;
            sets[n + i] = sets[x] & sets[y];
        } else if (tp == 3) {
            int x;
            cin >> x;
            sets[n + i] = univ & (~sets[x]);
        }
    }
    for (int i = 0; i < q; i++) {
        int x, v;
        cin >> x >> v;
        if (sets[x][v]) cout << "TAK\n";
        else cout << "NIE\n";
    }
    return 0;
}