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
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define piii pair<pair<int,int>, int>
#define st first.first
#define nd first.second
#define rd second
#define For(i, l, r) for (int i = l; i <= r; i++)
#define Forcin(l, r, a)        \
  for (int i = l; i <= r; i++) \
    cin >> a[i];
#define Ford(i, l, r) for (int i = l; i >= r; i--)
#define ben(v) v.begin(), v.end()
#define LOCAL 0
#define LOCAL2 0
using namespace std;
 
const int M = 400005, L=64*782;
int n, m, q;
//bitset <L> sets[M];
 
signed main()
{
  //cin.tie(0)->sync_with_stdio();
    if (LOCAL)
        freopen("a.txt", "r", stdin);
    if (LOCAL2)
        freopen("local_out.txt", "w", stdout);
    cerr << (M*L)/8/1024/1024 << " MB\n";
    cin>>n>>m>>q;
    vector <bitset<L>> sets(n+m+1);
    For(i, 1, n){
        for(int j=i;j<=n;j+=i){
            sets[i].set(j);
        }
    }
    For(i, n+1, n+m){
        int t, x, y;
        cin>>t>>x;
        if(t<3)
            cin>>y;
        if (t==1){
            sets[i]=(sets[x]|sets[y]);
        }
        else if (t==2){
            sets[i]=(sets[x]&sets[y]);
        }
        else{
            sets[i]=(~sets[x]);
        }
    }
    For(i, 1, q){
        int x,v;
        cin>>x>>v;
        cout << (sets[x].test(v) ? "TAK\n" : "NIE\n");
    }
}