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


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