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
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

constexpr int M = 50'000;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int n,m,q;
	cin >> n >> m >> q;
	vector<bitset<M>> bs(n+m);
	for(int i=0; i<n; ++i) {
		for(int j=i; j<n; j+=i+1) bs[i].set(j,1);
	}
	bitset<M> full;
	for(int i=0; i<M; ++i) full.set(i,1);
	for(int i=n; i<n+m; ++i) {
		int t; cin >> t;
		if(t==1) {
			int x, y;
			cin >> x >> y;
			bs[i] = bs[x-1] | bs[y-1];
		} else if(t==2) {
			int x, y;
			cin >> x >> y;
			bs[i] = bs[x-1] & bs[y-1];
		} else {
			int x; cin >> x;
			bs[i] = bs[x-1] ^ full;
		}
	}
	while(q--) {
		int a, b;
		cin >> a >> b;
		if(bs[a-1][b-1]) cout << "TAK\n";
		else cout << "NIE\n";
	}

	return 0;
}