#include <bits/stdc++.h>
using namespace std;
const int N = 501;
map<int, int> g[N];
int c[N], a, m, n;
bool dfs(int i, int p) {
  if (i == 0) return p;
  int k = i - 1;
  for (auto q : g[i]) {
    c[i] = q.second;
    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 j = 1; j <= m; ++j) cin >> a, g[i][a] = j;
  if (dfs(n, 0)) {
    cout << "TAK\n";
    for (int j = 1; j <= n; ++j) cout << c[j] << ' ';
  } else
    cout << "NIE";
}
