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
#include <cstdio>


int tab[32000000];


int n, m;

bool ok = false;

void rec(int i, int j)
{
  if (i < 0 || j < 0 || i >= n || j >= m)
    return;
  if (ok)
    return;
    
  if (tab[i * m + j])
  {
    return;
  }
  
  if (i == n - 1 && j == m - 1)
  {
    ok = true;
    return;
  }
  
  rec(i + 1, j);
  rec(i, j + 1);
}

int main()
{
  int k;
  scanf("%d %d %d", &n, &m, &k);
  
  
  int x = 0;
  for (int i = 0; i < k; i++)
  {
    int r, c, z;
    scanf("%d %d %d", &r, &c, &z);
    
    int r1 = r ^ x;
    r1 %= n;

    int c1 = c ^ x;
    c1 %= m;
    
    tab[r1 * m + c1] = 1;
    
    //printf("%d %d\n", r1, c1);
    
    ok = false;
    rec(0, 0);
    if (!ok)
    {
      printf("TAK\n");
      tab[r1 * m + c1] = 0;
      x ^= z;
    }
    else
    {
      printf("NIE\n");
    }
    
  }
  
  
  return 0;
}