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
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* -----------------------
Autor: Tomasz Boguslawski
-------------------------- */
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<sstream>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include <fstream>
#include<math.h>

#define LL long long
#define FOR(x, b, e) for(LL x = b; x <= (e); x++)
#define FORD(x, b, e) for(LL x = b; x >= (e); x--)
#define VAR(v, n) __typeof(n) v = (n)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define DEBUG if (debug)
#define MIN(a,b) ((a>b)?b:a)
#define MAX(a,b) ((a>b)?a:b)


using namespace std;

LL n, m, q;

unsigned long long bitArray[64];

class MySet
{
public:
    unsigned long long *num;
    LL c;
    MySet()
    {
        c = 1 + n/64;
        num = new unsigned long long[c];
        FOR(i,0,c-1) num[i]=0;
    }
    void setBit(LL a)
    {
        num[a/64]+=bitArray[a%64];
    }
    void init(LL k)
    {
        LL a = k;
        while (a<=n) { setBit(a); a+=k;}
        //FOR(i,0,c-1) cout << i << ":: " << num[i] << "\n";
    }
    void initFrom(MySet &another)
    {
        FOR(i,0,c-1) num[i]=another.num[i];
    }
    bool what(LL a)
    {
        return (num[a/64]&(bitArray[a%64])) > 0;
    }
    void neg()
    {
        FOR(i,0,c-1) num[i]=~num[i];
    }
    void add(MySet &another)
    {
        FOR(i,0,c-1) num[i] = ((num[i]) | (another.num[i]));
    }
    void cross(MySet &another)
    {
        FOR(i,0,c-1) num[i] = ((num[i]) & (another.num[i]));
    }

};

MySet *sets;

/// MAIN
int main(int argc, char* argv[])
{
    // magic formula, which makes streams work faster:
	ios_base::sync_with_stdio(0);
	unsigned long long a = 1;
	FOR(i,0,63) { bitArray[i]=a; a*=2; }
    cin >> n; cin >> m; cin >> q;

    sets = new MySet[n+m+1];
    FOR(i,1,n) sets[i].init(i);
    int op, s1, s2;
    FOR(i,1,m)
    {
        cin >> op; cin >> s1; if (op<3) cin >> s2;
        sets[n+i].initFrom(sets[s1]);
        if (op==1)
        {
            sets[n+i].add(sets[s2]);
        }
        else if (op==2)
        {
            sets[n+i].cross(sets[s2]);
        }
        else
        {
            sets[n+i].neg();
        }
    }

    LL v;
    FOR(i,1,q)
    {
        cin >> s1; cin >> v;
        if (sets[s1].what(v)) cout << "TAK\n"; else cout << "NIE\n";
    }
    return 0;
};