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
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>

#define ll long long
#define fors(u, n, s) for(ll u = (s); u < (n); u++)
#define foru(u, n) fors(u, n, 0)

using namespace std;

const int N = 50000+100;
const int M = 400000+100;

int n, m, q;

vector<bitset<N>> sets;

int main()
{
    sets.resize(N+M);
    foru(i, N+M) sets[i] = 0;

    cin >> n >> m >> q;

    foru(i, n){
        int j = i+1;
        while(j <= n){
            sets[i][j-1] = true;
            j += i+1;
        }
    }

    foru(i, m){
        int c; cin >> c;
        if (c == 1) {
            int x, y; cin >> x >> y; x--; y--;
            sets[n+i] = sets[x] | sets[y];
        } else if (c == 2) {
            int x, y; cin >> x >> y; x--; y--;
            sets[n+i] = sets[x] & sets[y];
        } else {
            int x; cin >> x; x--;
            sets[n+i] = ~sets[x];
        }
    }

    /*cout << "============" << endl;

    foru(i, n+m) {
        foru(j, n){
            cout << sets[i][j];
        }
        cout << endl;
    }

    cout << "============" << endl;*/

    foru(_i, q) {
        int x, v; cin >> x >> v;
        x--; v--;
        if(sets[x][v]) {
            cout << "TAK\n";
        } else {
            cout << "NIE\n";
        }
    }

    return 0;
}