#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
int a[505][505], dp[505][1025], nxt[505][1025];
int foo(int indx, int xr) {
  if (indx > n) {
    return xr;
  }
  if (dp[indx][xr] != -1) return dp[indx][xr];
  for (int i = 1; i <= m; ++i) {
    int val = foo(indx + 1, xr ^ a[indx + 1][i]);
    if (val > dp[indx][xr]) {
      dp[indx][xr] = val;
      nxt[indx][xr] = i;
    }
  }
  return dp[indx][xr];
}
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> a[i][j];
  for (int i = 0; i < n + 5; ++i)
    for (int j = 0; j < 1025; ++j) dp[i][j] = -1;
  dp[0][0] = foo(0, 0);
  if (dp[0][0] <= 0) {
    cout << "NIE\n";
    return;
  }
  cout << "TAK\n";
  int xr = 0;
  for (int i = 0; i < n; ++i) {
    cout << nxt[i][xr] << " ";
    xr = xr ^ a[i + 1][nxt[i][xr]];
  }
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
