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
// Homura Akemi a.k.a. Starrykiller (/user/235125)
// I love Madoka Kaname forever! 
#include <bits/stdc++.h>

using namespace std;

auto range(auto l, auto r) { return views::iota(l,r); }
auto rev=views::reverse;

_GLIBCXX_ALWAYS_INLINE void chmax(auto &a, auto b) { a=max(a,b); }
_GLIBCXX_ALWAYS_INLINE void chmin(auto &a, auto b) { a=min(a,b); }

constexpr int MAXN=50000;

using bs=bitset<MAXN>;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
[]{
    
    int n, m, q; cin>>n>>m>>q;
    vector<bs> a(n+m);
    for (int i=1; i<=n; ++i) {
        auto &now=a[i-1];
        for (int j=1; i*j<=n; ++j) now.set(i*j-1);
    }
    for (int i=0; i<m; ++i) {
        int op, x, y;
        cin>>op>>x; --x;
        if (op!=3) cin>>y, --y;
        if (op==1) a[n+i]=a[x]|a[y];
        else if (op==2) a[n+i]=a[x]&a[y];
        else a[n+i]=a[x], a[n+i].flip();
    }
    while (q--) {
        int x, v; cin>>x>>v;
        --x; --v;
        if (a[x].test(v)) cout<<"TAK\n";
        else cout<<"NIE\n";
    }
}();
}