#include <bits/stdc++.h>
using namespace std;
bool find_path(bool **island, int N, int M)
{
queue<pair<int, int>> Q;
Q.push({N - 1, M - 1});
while (!Q.empty())
{
pair<int, int> current = Q.front();
Q.pop();
if (island[current.first][current.second] == false)
continue;
if (current.first == 0 && current.second == 0)
return true;
if (current.first > 0)
Q.push({current.first - 1, current.second});
if (current.second > 0)
Q.push({current.first, current.second - 1});
}
return false;
}
void solve()
{
int M, N, K;
cin >> N >> M >> K;
bool **island = new bool *[N];
for (int i = 0; i < N; i++)
island[i] = new bool[M];
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
island[i][j] = true;
int X = 0;
for (int _ = 0; _ < K; _++)
{
int R, C, Z;
cin >> R >> C >> Z;
int i, j;
i = (R ^ X) % N;
j = (C ^ X) % M;
island[i][j] = false;
if (!find_path(island, N, M))
{
island[i][j] = true;
X = X ^ Z;
cout << "TAK\n";
}
else
cout << "NIE\n";
}
for (int i = 0; i < N; i++)
delete[] island[i];
delete[] island;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}