#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[505][505];
long long dp[505][1030];
long long par[505];
long long gg;
long long rec(long long level, long long myxor, long long col) {
  if (level == n) {
    if (myxor > 0) {
      par[level] = col;
      return 1;
    } else
      return 0;
  }
  if (dp[level][myxor] != -1) return dp[level][myxor];
  long long ans = 0;
  for (long long i = 0; i < m; i++) {
    if (rec(level + 1, myxor ^ a[level][i], i + 1)) {
      ans = 1;
      par[level] = col;
      break;
    }
  }
  return dp[level][myxor] = ans;
}
long long solve() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> a[i][j];
  memset(dp, -1, sizeof(dp));
  long long ans = rec(0, 0, 0);
  if (ans) {
    vector<long long> allcol;
    long long level = n;
    while (level > 0) {
      allcol.push_back(par[level]);
      level--;
    }
    reverse(allcol.begin(), allcol.end());
    cout << "TAK" << endl;
    for (long long i = 0; i < n; i++) cout << allcol[i] << " ";
    cout << endl;
  } else {
    cout << "NIE" << endl;
  }
  return 0;
}
signed main() {
  long long t;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
