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
from sys import stdin

ops = []
memo = {}
n, m, q = [int(x) for x in stdin.readline().rstrip().split(" ")]
for i in range(m):
    line = stdin.readline().rstrip().split(" ")
    if len(line) == 2:
        op, s = [int(x) for x in line]
        ops.append([op, s])
    else:
        op, s1, s2 = [int(x) for x in line]
        ops.append([op, s1, s2])

def calc(x, v1):
    if x <= n:
        return True if v1 % x == 0 else False
    else:
        if (x, v1) not in memo:
            if ops[x - n - 1][0] == 1:
                memo[(x, v1)] = calc(ops[x - n - 1][1], v1) or calc(ops[x - n - 1][2], v1)
            elif ops[x - n - 1][0] == 2:
                 memo[(x, v1)] = calc(ops[x - n - 1][1], v1) and calc(ops[x - n - 1][2], v1)
            elif ops[x - n - 1][0] == 3:
                memo[(x, v1)] = not calc(ops[x - n - 1][1], v1)
        return memo[(x, v1)]
        #x-n-1

for i in range(q):
    x, v = [int(x) for x in stdin.readline().rstrip().split(" ")]
    print("TAK" if calc(x, v) else "NIE")