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
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("popcnt")
typedef long long LL;

vector<bitset<50002>> v;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	LL n, m, q;
	cin>>n>>m>>q;
	v.resize(n+m+1);
	for(int i=1; i<=n; i++){
		for(int j=i; j<=n; j+=i){
			v[i][j]=1;
		}
	}
	for(int i=n+1; i<=n+m; i++){
		int type;
		cin>>type;
		LL x, y;
		if(type == 1){
			cin>>x>>y;
			v[i] = v[x]|v[y];
		}
		if(type == 2){
			cin>>x>>y;
			v[i] = v[x]&v[y];
		}
		if(type == 3){
			cin>>x;
			v[i] = ~v[x];
		}
	}
	while(q--){
		int x, y;
		cin>>x>>y;
		if(v[x][y]){
			cout<<"TAK\n";
		}else{
			cout<<"NIE\n";
		}
	}
	return 0;
}