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
85
86
87
88
89
90
91
92
93
94
#include <bitset>
#include <vector>
#include <iostream>
#include <cassert>


struct Zbior
{
    std::bitset<50001> elementy;
};

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

    /*
    std::cout << "50000 400000 1000000\n";
    for (int i = 0; i < 400000; ++i)
    {
        int operato = (rand() % 3) + 1;
        if (operato == 1)
            std::cout << "1 " << ((rand() % 400000) + 1) << " " << ((rand() % 400000) + 1) << "\n";
        if (operato == 2)
            std::cout << "2 " << ((rand() % 400000) + 1) << " " << ((rand() % 400000) + 1) << "\n";
        if (operato == 3)
            std::cout << "3 " << ((rand() % 400000) + 1) << "\n";
    }

    for (int i = 0; i < 1000000; ++i)
    {
        std::cout << ((rand() % 450000) + 1) << " " << ((rand() % 50000) + 1) << "\n";
    }
    return 0;*/

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

    std::vector<Zbior> zbiory;
    zbiory.push_back(Zbior());
    for (int i = 0; i < n; ++i)
    {
        zbiory.push_back(Zbior());
    }
    for (int j = 1; j <= n; ++j)
    {
        for (int i = j; i <= n; i +=j)
            zbiory[j].elementy.set(i, true);
    }
    for (int i = 0; i < m; ++i)
    {
        int operato;
        std::cin >> operato;
        if (operato == 1)
        {
            int pierwszy;
            int drugi;
            std::cin >> pierwszy >> drugi;
            Zbior zbior;
            zbior.elementy = zbiory[pierwszy].elementy | zbiory[drugi].elementy;
            zbiory.push_back(zbior);
        }
        if (operato == 2)
        {
            int pierwszy;
            int drugi;
            std::cin >> pierwszy >> drugi;
            Zbior zbior;
            zbior.elementy = zbiory[pierwszy].elementy & zbiory[drugi].elementy;
            zbiory.push_back(zbior);
        }
        if (operato == 3)
        {
            int pierwszy;
            std::cin >> pierwszy;
            Zbior zbior;
            zbior.elementy = ~zbiory[pierwszy].elementy;
            zbiory.push_back(zbior);
        }
    }
    for (int i = 0; i < q; ++i)
    {
        int numerZbioru;
        int liczba;
        std::cin >> numerZbioru >> liczba;
        if (zbiory[numerZbioru].elementy.test(liczba))
            std::cout << "TAK\n";
        else
            std::cout << "NIE\n";
    }
    return 0;
}