#include <bits/stdc++.h>
using namespace std;
const int N = 501, P = 1024;
map<int, vector<int>> g[N];
int c[N], m, n;
bool dfs(int i, int p) {
  if (i == 0) {
    if (p == 0) return false;
    cout << "TAK\n";
    for (int j = 1; j <= n; ++j) cout << c[j] << ' ';
    return true;
  }
  int j, k = i - 1;
  for (auto q : g[i]) {
    c[i] = q.second.front();
    if (dfs(k, p ^ q.first)) return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr),
      cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int a, j = 1; j <= m; ++j) cin >> a, g[i][a].push_back(j);
  if (not dfs(n, 0)) cout << "NIE";
}
