#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int N, M, chk[1111][1111], A[1111][1111], pos[1111][1111], path[1111][1111];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) {
      cin >> A[i][j];
    }
  for (int i = 1; i <= M; i++) chk[1][A[1][i]] = 1, path[1][A[1][i]] = i;
  for (int i = 2; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      for (int k = 0; k <= 1023; k++) {
        if (chk[i - 1][k]) {
          chk[i][k ^ A[i][j]] = 1;
          path[i][k ^ A[i][j]] = j;
        }
      }
    }
  }
  bool poss = 0;
  int v;
  for (int i = 1; i <= 1023; i++) {
    if (chk[N][i]) {
      poss = 1;
      v = i;
      break;
    }
  }
  if (poss) {
    cout << "TAK\n";
    vector<int> ans;
    for (int i = N; i >= 1; i--) {
      ans.push_back(path[i][v]);
      v = v ^ A[i][path[i][v]];
    }
    for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << ' ';
  } else
    cout << "NIE";
}
