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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>

#define trueOpIndex index-n-1
#define CURRENT_OPERATION operations[index-n-1]

struct Operation{
    int left;
    int right;
    char type;// 1-sum 2-product 3-negation(right = undefined)
};



bool inSubset(int value, int index, int n, Operation* operations){
    if(index<=n){
        return !(value%index);
    }

    switch(operations[trueOpIndex].type){
        case '1':
            return inSubset(value, CURRENT_OPERATION.left, n, operations) 
                || inSubset(value, CURRENT_OPERATION.right, n, operations);

        case '2':
            return inSubset(value, CURRENT_OPERATION.left, n, operations) 
            && inSubset(value, CURRENT_OPERATION.right, n, operations);

        case '3':
            return !(inSubset(value, CURRENT_OPERATION.left, n, operations));
        default:
            return false;
        }
    return false;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    unsigned int n, m, q;
    std::cin >> n >> m >> q;

    Operation* operations = (Operation*)malloc(sizeof(Operation)*m);


    for(int i = 0; i < m; i++){
        Operation op;

        char type;
        int left;
        std::cin >> type >> left;
        op.left = left;
        op.type = type;
        
        if(type == '3'){
            operations[i] = op;
            continue;
        }

        int right;
        std::cin >> right;
        op.right = right;

        operations[i] = op;
    }


    for(int i = 0; i < q; i++){
        int subsetIndex, value;
        std::cin >> subsetIndex >> value;

        if(value <= n && inSubset(value,subsetIndex,n,operations)){
            std::cout << "TAK\n";
        }
        else{
            std::cout<< "NIE\n";
        }
    }
    
    free(operations);

    return 0;
}