Student Dima from Kremland has a matrix $a$ of size $n \times m$ filled with non-negative integers.

He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!

Formally, he wants to choose an integers sequence $c_1, c_2, \ldots, c_n$ ($1 \leq c_j \leq m$) so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds, where $a_{i, j}$ is the matrix element from the $i$-th row and the $j$-th column.

Here $x \oplus y$ denotes the bitwise XOR operation of integers $x$ and $y$.


-----Input-----

The first line contains two integers $n$ and $m$ ($1 \leq n, m \leq 500$) — the number of rows and the number of columns in the matrix $a$.

Each of the next $n$ lines contains $m$ integers: the $j$-th integer in the $i$-th line is the $j$-th element of the $i$-th row of the matrix $a$, i.e. $a_{i, j}$ ($0 \leq a_{i, j} \leq 1023$). 


-----Output-----

If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".

Otherwise print "TAK" in the first line, in the next line print $n$ integers $c_1, c_2, \ldots c_n$ ($1 \leq c_j \leq m$), so that the inequality $a_{1, c_1} \oplus a_{2, c_2} \oplus \ldots \oplus a_{n, c_n} > 0$ holds. 

If there is more than one possible answer, you may output any.


-----Examples-----
Input
3 2
0 0
0 0
0 0

Output
NIE

Input
2 3
7 7 7
7 7 10

Output
TAK
1 3 



-----Note-----

In the first example, all the numbers in the matrix are $0$, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.

In the second example, the selected numbers are $7$ (the first number in the first line) and $10$ (the third number in the second line), $7 \oplus 10 = 13$, $13$ is more than $0$, so the answer is found.

Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Bit manipulation

Complete search

Constructive algorithms
Skill types: Dynamic programming

Bit manipulation

Complete search

Starter code:

Solutions:
(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
x = 0
c = [1] * (n - 1)
for i in range(n - 1):
	x = x ^ a[i][0]
f = 0
for j in range(m):
	if a[n - 1][j] != x:
		c.append(j + 1)
		f = 1
		break
if f == 1:
	print('TAK')
	print(*c)
else:
	r = 0
	for i in range(n - 1):
		for j in range(1, m):
			if a[i][j] != a[i][0]:
				f = 1
				r = i
				c[i] = j + 1
				break
		if f == 1:
			break
	if f == 1:
		x = 0
		for i in range(n - 1):
			if i == r:
				x = x ^ a[i][c[i] - 1]
			else:
				x = x ^ a[i][0]
		for j in range(m):
			if a[n - 1][j] != x:
				c.append(j + 1)
				break
		print('TAK')
		print(*c)
	else:
		print('NIE')


(n, m) = map(int, input().split())
le = []
ans = [1] * n
ans1 = []
flag = True
for i in range(n):
	xx = list(map(int, input().split()))
	ans1.append(xx[0])
	if flag:
		f1 = False
		for j in range(m):
			if xx[j] != xx[0]:
				f1 = True
				flag = False
				break
		if f1:
			le = [i, 0, j]
su = 0
for i in range(n):
	su ^= ans1[i]
if su != 0:
	print('TAK')
	print(*ans)
elif le:
	ans[le[0]] = le[2] + 1
	print('TAK')
	print(*ans)
else:
	print('NIE')


from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
a = [list(map(int, stdin.readline().split())) for i in range(n)]
isDiff = False
(p, q) = (-1, -1)
for i in range(n):
	cval = a[i][0]
	for j in range(1, m):
		if cval is not a[i][j]:
			isDiff = True
			(p, q) = (i, j)
			break
	if isDiff:
		break
if not isDiff:
	x = 0
	for i in range(n):
		x ^= a[i][0]
	if not x:
		print('NIE')
	else:
		print('TAK')
		for i in range(n):
			print('1', end=' ')
		print()
else:
	x = 0
	for i in range(n):
		x ^= a[i][0]
	if x:
		print('TAK')
		for i in range(n):
			print('1', end=' ')
		print()
	else:
		print('TAK')
		for i in range(n):
			print(q + 1, end=' ') if i == p else print('1', end=' ')
		print()


import random, time
(n, m) = [int(i) for i in input().split()]
z = []
for salfjaslfj in range(n):
	z.append([int(i) for i in input().split()])
t = time.time()
while True:
	chi = []
	for i in range(n):
		chi.append(random.randint(0, m - 1))
	xors = 0
	for i in range(n):
		xors = xors ^ z[i][chi[i]]
	if xors != 0:
		print('TAK')
		print(' '.join([str(i + 1) for i in chi]))
		break
	tn = time.time()
	if tn - t > 0.85:
		print('NIE')
		break


def goDeep(index, currvals):
	if index == n:
		v = 0
		for i in range(n):
			v ^= currvals[i]
		if v != 0:
			print('TAK')
			tbp = [-1] * n
			for i in range(n):
				tbp[i] = str(grid[i].index(currvals[i]) + 1)
			print(*tbp)
			exit()
		return
	for val in sets[index]:
		currvals[index] = val
		goDeep(index + 1, currvals)
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
(n, m) = kk()
(grid, sets) = ([None] * n, [None] * n)
for i in range(n):
	ls = ll()
	grid[i] = ls
	sets[i] = set(ls)
goDeep(0, [0] * n)
print('NIE')


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(r, c) = value()
a = []
ele = set()
for i in range(r):
	a.append(array())
	for j in a[-1]:
		ele.add(j)
ans = {}
xor = 0
for i in range(r):
	xor ^= a[i][0]
	ans[i] = 1
if xor != 0:
	print('TAK')
	print('1 ' * r)
else:
	flag = False
	for i in range(r):
		if len(set(a[i])) != 1 and xor == 0:
			xor ^= a[i][0]
			for j in range(1, c):
				if a[i][j] != a[i][0]:
					flag = True
					ans[i] = j + 1
					xor ^= a[i][j]
					break
	if flag:
		print('TAK')
		print(*ans.values())
	else:
		print('NIE')


import collections as cc
import itertools as it
I = lambda : list(map(int, input().split()))
(n, m) = I()
a = [I() for i in range(n)]
temp = [0] * n
s = 0
ans = [1] * n
for i in range(n):
	temp[i] = a[i][0]
	s ^= a[i][0]
if s:
	print('TAK')
	print(*ans)
else:
	for i in range(n):
		tf = 0
		for j in range(m):
			if temp[i] != a[i][j]:
				ans[i] = j + 1
				tf = 1
				break
		if tf:
			break
	if tf:
		print('TAK')
		print(*ans)
	else:
		print('NIE')


X = list(map(int, input().split()))
Answer = [1] * X[0]
Check = False
Index = 0
SequenceNumber = 0
SUMXOR = 0
for _ in range(X[0]):
	Temp = list(map(int, input().split()))
	SUMXOR ^= Temp[0]
	if not Check:
		if Temp.count(Temp[0]) != X[1]:
			Check = True
			SequenceNumber = _
			for i in range(X[1]):
				if Temp[i] != Temp[0]:
					Index = i + 1
					break
if SUMXOR == 0 and (not Check):
	print('NIE')
	exit()
if SUMXOR != 0:
	print('TAK')
	print(*Answer)
	exit()
print('TAK')
Answer[SequenceNumber] = Index
print(*Answer)


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
ans = 0
out = []
for i in range(n):
	ans ^= l[i][0]
if ans != 0:
	print('TAK')
	print('1 ' * n)
else:
	out = [1] * n
	for i in range(n):
		for j in range(m):
			if ans ^ l[i][j] ^ l[i][0] != 0:
				out[i] = j + 1
				print('TAK')
				print(*out)
				quit()
	print('NIE')


(n, m) = map(int, input().split())
matrix = []
for i in range(n):
	matrix.append([int(x) for x in input().split()])
all_1 = True
for row in matrix:
	if len(set(row)) > 1:
		all_1 = False
		print('TAK')
		break
if all_1:
	v = 0
	for row in matrix:
		v ^= row[0]
	if v == 0:
		print('NIE')
	else:
		print('TAK')
		print(*[1] * n)
else:
	ans = [0] * n
	v = 0
	for row in matrix:
		v ^= row[0]
	if v == 0:
		j = 0
		for i in range(n):
			row = matrix[i]
			if len(set(row)) > 1:
				j = i
				break
		for i in range(m):
			if v ^ matrix[j][0] ^ matrix[j][i] != 0:
				ans[j] = i
				break
	for a in ans:
		print(a + 1, end=' ')


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
ans = [1] * n
c = a[0][0]
for i in range(1, n):
	c ^= a[i][0]
if c:
	print('TAK')
	print(*ans)
else:
	flag = False
	for i in range(n):
		if len(set(a[i])) > 1:
			flag = True
			for j in range(m):
				if a[i][j] != a[i][0]:
					ans[i] = j + 1
					break
			break
	if not flag:
		print('NIE')
	else:
		print('TAK')
		print(*ans)


import sys
s = list(map(int, input().split()))
mapper = []
for i in range(s[0]):
	l = list(map(int, input().split()))
	mapper.append(l)
xor = 0
for i in range(s[0]):
	xor = mapper[i][0] ^ xor
if xor != 0:
	print('TAK')
	ans = ''
	for i in range(s[0]):
		ans += str(1)
		ans += ' '
	print(ans)
else:
	for i in range(s[0]):
		for j in range(s[1]):
			if mapper[i][j] != mapper[i][0]:
				print('TAK')
				ans = ''
				for k in range(s[0]):
					if k == i:
						ans += str(j + 1)
					else:
						ans += str(1)
					ans += ' '
				print(ans)
				sys.exit(0)
	print('NIE')


def in_int():
	return int(input())

def in_list():
	return [int(x) for x in input().split()]
(n, m) = in_list()
mat = []
first = -1
for i in range(n):
	mat.append(in_list())
	if first == -1:
		for j in range(m - 1):
			if mat[-1][j] != mat[-1][j + 1]:
				first = (i, j)
				break
if first == -1:
	ans = 0
	for i in range(n):
		ans = ans ^ mat[i][0]
	if ans > 0:
		print('TAK')
		print(' '.join(['1'] * n))
	else:
		print('NIE')
else:
	(r, c) = first
	print('TAK')
	ans = 0
	for i in range(n):
		if i != r:
			ans = ans ^ mat[i][0]
		else:
			ans = ans ^ mat[i][c]
	if ans > 0:
		for i in range(n):
			if i != r:
				print(0 + 1, end=' ')
			else:
				print(c + 1, end=' ')
	else:
		for i in range(n):
			if i != r:
				print(0 + 1, end=' ')
			else:
				print(c + 2, end=' ')


import sys
(n, m) = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(n)]
kek = False
for x in arr:
	for i in range(m - 1):
		if x[i] != x[i + 1]:
			kek = True
val = 0
for i in range(n):
	val ^= arr[i][0]
if val > 0:
	print('TAK')
	print('1 ' * n)
	sys.exit(0)
if not kek and val == 0:
	print('NIE')
	sys.exit(0)
for i in range(n):
	for j in range(m - 1):
		if arr[i][j] != arr[i][j + 1]:
			print('TAK')
			print('1 ' * i + str(j + 2) + ' ' + '1 ' * (n - i - 1))
			sys.exit(0)


def can(b, n):
	flag = [[False] * 2 for _ in range(n + 1)]
	flag[n][0] = True
	for i in range(n - 1, -1, -1):
		flag[i][0] = flag[i + 1][0] and b[i][0] != -1 or (flag[i + 1][1] and b[i][1] != -1)
		flag[i][1] = flag[i + 1][0] and b[i][1] != -1 or (flag[i + 1][1] and b[i][0] != -1)
	if not flag[0][1]:
		return False
	else:
		print('TAK')
		now = 1
		string = ''
		for i in range(n):
			if now == 0:
				if flag[i + 1][0] and b[i][0] != -1:
					now = 0
					string += str(b[i][0] + 1) + ' '
				else:
					now = 1
					string += str(b[i][1] + 1) + ' '
			elif flag[i + 1][0] and b[i][1] != -1:
				now = 0
				string += str(b[i][1] + 1) + ' '
			else:
				now = 1
				string += str(b[i][0] + 1) + ' '
		print(string[:-1])
		return True

def ma():
	(n, m) = [int(i) for i in input().split(' ')]
	grid = []
	for i in range(n):
		grid.append([int(j) for j in input().split(' ')])
	for k in range(10):
		b = [[-1] * 2 for _ in range(n)]
		for i in range(n):
			for j in range(m):
				if grid[i][j] & 1 << k:
					b[i][1] = j
				else:
					b[i][0] = j
		if can(b, n):
			return
	print('NIE')
	return
ma()


import heapq
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7

def main():
	(n, m) = map(int, input().split())
	a = [list(map(int, input().split())) for i in range(n)]
	xor = 0
	for i in range(n):
		xor ^= a[i][0]
	l = [1] * n
	if xor > 0:
		print('TAK')
		print(*l)
		exit()
	for i in range(n):
		for j in range(1, m):
			if xor ^ a[i][j] ^ a[i][0] > 0:
				l[i] = j + 1
				xor ^= a[i][j]
				xor ^= a[i][0]
				if xor > 0:
					print('TAK')
					print(*l)
					exit()
	print('NIE')
main()


R = lambda : map(int, input().split())
(n, m) = R()
a = [[*R()] for _ in [0] * n]
s = i = 0
for r in a:
	s ^= r[0]
t = [1] * n
for r in a:
	j = 0
	for x in r:
		if s ^ r[0] ^ x:
			t[i] = j + 1
			print('TAK', *t)
			exit()
		j += 1
	i += 1
print('NIE')


(n, m) = list(map(int, input().split()))
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
c = []
q = []
for i in range(n):
	b = -1
	w = 0
	for j in range(m):
		if b == -1:
			if a[i][j] != b:
				b = a[i][j]
				w = j
		elif a[i][j] != b:
			q.append(a[i][j])
			q.append(j + 1)
			q.append(i)
			break
	c.append([b, w + 1])
s = 0
for i in c:
	s ^= i[0]
if s != 0:
	print('TAK')
	for i in c:
		print(i[1], end=' ')
elif q == []:
	print('NIE')
else:
	print('TAK')
	for i in range(n):
		if i == q[2]:
			print(q[1], end=' ')
		else:
			print(c[i][1], end=' ')


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append([int(i) for i in input().split()])
c = [0] * n

def check():
	ans = 0
	for i in range(n):
		ans ^= a[i][c[i]]
	return ans
while check() == 0:
	flag = 0
	for i in range(n):
		if c[i] + 1 < m:
			flag = 1
	if flag == 0:
		print('NIE')
		break
	flag = 0
	for i in range(n):
		while c[i] + 1 < m:
			c[i] = c[i] + 1
			if a[i][c[i]] != a[i][c[i] - 1]:
				flag = 1
				break
		if flag == 1:
			break
		else:
			pass
else:
	print('TAK')
	c = map(lambda x: x + 1, c)
	print(*c)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
(n, m) = mp()
ml = []
t = True
x = 0
ind = 0
for i in range(n):
	l = lmp()
	if t and len(set(l)) != 1:
		t = False
		ind = i
	else:
		x ^= l[0]
	ml.append(l)
if t:
	if x == 0:
		print('NIE')
	else:
		print('TAK')
		print(*[1 for i in range(n)])
else:
	print('TAK')
	for i in range(n):
		if i != ind:
			print(1, end=' ')
		else:
			for j in range(m):
				if ml[i][j] != x:
					print(j + 1, end=' ')
					break
	print()


def solve():
	entrada = input().split()
	n = int(entrada[0])
	m = int(entrada[1])
	temp = 0
	arr_c = [[0 for x in range(5 * pow(10, 2) + 4)] for y in range(5 * pow(10, 2) + 4)]
	for i in range(0, n):
		entrada = input().split()
		for j in range(0, m):
			arr_c[i][j] = int(entrada[j])
	for i in range(n):
		temp ^= arr_c[i][0]
	if temp != 0:
		print('TAK')
		for i in range(n):
			print('1', end=' ')
			print()
		return
	else:
		for i in range(n):
			for j in range(1, m):
				if arr_c[i][j] != arr_c[i][0]:
					print('TAK')
					for k in range(n):
						if k != i:
							print('1', end=' ')
						else:
							print(j + 1, end=' ')
					print()
					return
		print('NIE')
		return
solve()


from sys import stdin, stdout
for _ in range(1):
	(r, c) = list(map(int, stdin.readline().split()))
	a = [list(map(int, stdin.readline().split())) for _ in range(r)]
	xor = 0
	f = 0
	for i in range(r):
		xor ^= a[i][0]
	if xor > 0:
		print('TAK')
		print(*[1 for i in range(r)])
		continue
	ans = [1 for i in range(r)]
	for i in range(r):
		for j in range(c):
			if a[i][j] != a[i][0]:
				ans[i] = j + 1
				f = 1
				break
		if f:
			break
	if f:
		print('TAK')
		print(*ans)
	else:
		print('NIE')


import os
import heapq
import sys, threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10 ** 5)
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def main():
	t = 1
	for _ in range(t):
		(n, m) = inar()
		matrix = []
		for i in range(n):
			take = inar()
			matrix.append(take)
		check = matrix[0][0]
		count = 0
		for i in range(n):
			for j in range(m):
				if matrix[i][j] == check:
					count += 1
		if count == n * m and check == 0:
			print('NIE')
		elif n % 2 == 0 and count == n * m:
			print('NIE')
		elif n % 2 != 0 and count == n * m:
			print('TAK')
			res = [1] * n
			print(*res)
		else:
			row = -1
			for i in range(n):
				dic = defaultdict(int)
				for j in range(m):
					dic[matrix[i][j]] += 1
				if len(dic) > 1:
					row = i
					break
			if row == -1:
				temp = 0
				for i in range(n):
					temp = temp ^ matrix[i][0]
				if temp == 0:
					print('NIE')
				else:
					print('TAK')
					res = [1] * n
					print(*res)
			else:
				ans = 0
				res = [0] * n
				for i in range(n):
					if i == row:
						continue
					ans = ans ^ matrix[i][0]
					res[i] = 1
				for i in range(m):
					if ans ^ matrix[row][i] != 0:
						res[row] = i + 1
						break
				print('TAK')
				print(*res)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def bitwise_xor(a, b):
	return a ^ b
pre = 0
flg = -1
(n, m) = map(int, input().split())
a = [[] for i in range(n)]
for i in range(n):
	a[i] = list(map(int, input().split()))
ans = [[0, 0] for _ in range(n)]
for i in range(n):
	Ma = max(a[i])
	Mi = min(a[i])
	if Ma == Mi:
		ans[i] = [1, 1]
	else:
		flg = i
		for j in range(m):
			if a[i][j] == Ma:
				ans[i][0] = j + 1
			if a[i][j] == Mi:
				ans[i][1] = j + 1
ct = 0
for i in range(n):
	ct = bitwise_xor(pre, a[i][ans[i][0] - 1])
	pre = ct
if ct == 0 and flg == -1:
	print('NIE')
else:
	print('TAK')
	for i in range(n):
		print(ans[i][0 + 1 if ct == 0 and i == flg else 0])


(n, m) = tuple(map(int, input().rstrip().split()))
a = []
for _ in range(n):
	a.append(list(map(int, input().rstrip().split())))
c = [1 for _ in range(n)]

def bxr():
	s = 0
	for i in range(n):
		s ^= a[i][c[i] - 1]
	if s > 0:
		print('TAK')
		print(' '.join(map(str, c)))
	else:
		for i in range(n):
			for j in range(m):
				if a[i][j] != a[i][c[i] - 1]:
					c[i] = j + 1
					print('TAK')
					print(' '.join(map(str, c)))
					return
		print('NIE')
bxr()


from functools import reduce

def main():
	(n, m) = list(map(int, input().split()))
	mat = [list(map(int, input().split())) for i in range(n)]
	for i in range(n):
		mat[i] = list(enumerate(mat[i]))
	l = []
	for i in range(n):
		s = set()
		x = []
		for j in range(m):
			if mat[i][j][1] not in s:
				s.add(mat[i][j][1])
				x.append(mat[i][j])
		l.append(x)
	a = 0
	for i in l:
		a ^= i[0][1]
	if a > 0:
		print('TAK')
		print(*[1] * n)
	else:
		(index, val) = (-1, 0)
		for (j, i) in enumerate(l):
			if len(i) > 1:
				index = j
				val = i[1][0] + 1
				break
		if index == -1:
			print('NIE')
		else:
			u = [1] * n
			u[j] = val
			print('TAK')
			print(*u)
main()


(n, m) = [int(i) for i in input().split()]
A = []
C = []
for i in range(n):
	B = [int(j) for j in input().split()]
	A.append(B)
	C.append(sorted(list(set(B))))
xor = 0
ans = []
for i in range(n):
	xor ^= A[i][0]
	ans.append(1)
if xor == 0:
	found = 0
	for trial in range(n - 1, -1, -1):
		newxor = xor ^ A[trial][0]
		if found == 1:
			break
		for j in range(m):
			if A[trial][j] ^ newxor != 0:
				ans[trial] = j + 1
				found = 1
				break
		if found == 1:
			break
	if found:
		print('TAK')
		print(*ans)
	else:
		print('NIE')
else:
	print('TAK')
	print(*ans)


import sys, math, queue
MOD = 10 ** 9 + 7
(n, m) = map(int, input().split())
d = [{} for i in range(n)]
g = []
for i in range(n):
	g.append(list(map(int, input().split())))
	for j in range(m):
		d[i][g[i][j]] = j
ans = [1 for i in range(n)]
xor = g[0][0]
for i in range(1, n):
	xor = xor ^ g[i][0]
if xor == 0:
	possible = False
	for i in range(n):
		if len(d[i]) > 1:
			for k in d[i]:
				if k != g[i][0]:
					ans[i] = d[i][k] + 1
					possible = True
					break
			break
else:
	possible = True
if not possible:
	print('NIE')
else:
	print('TAK')
	print(*ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(n)]
smat = [set(r) for r in mat]
xor = 0
for i in range(n):
	xor ^= mat[i][0]
if xor > 0:
	print('TAK')
	print(' '.join(map(str, [1] * n)))
	sys.exit(0)
else:
	if all((len(r) == 1 for r in smat)):
		print('NIE')
		sys.exit(0)
	for gr in range(n):
		if len(smat[gr]) > 1:
			break
	for j in range(m):
		if xor ^ mat[gr][0] ^ mat[gr][j] > 0:
			print('TAK')
			inds = [1] * n
			inds[gr] = j + 1
			print(' '.join(map(str, inds)))
			sys.exit(0)


(n, m) = map(int, input().split())
arr1 = [[int(el) for el in input().split()] for _ in range(n)]
res = 0
for i in range(n):
	res ^= arr1[i][0]
if res:
	print('TAK')
	print(*[1 for _ in range(n)])
else:
	res = [1] * n
	for i in range(n):
		for j in range(m):
			if arr1[i][j] != arr1[i][0]:
				res[i] = j + 1
				print('TAK')
				print(*res)
				exit()
	print('NIE')


(n, m) = list(map(int, input().split()))
mat = [list(map(int, input().split())) for _ in range(n)]
res = []
for i in range(n):
	prev = -1
	for j in range(m):
		if prev == -1:
			prev = mat[i][j]
		elif prev != mat[i][j]:
			xr = 0
			for k in range(n):
				if k != i:
					xr ^= mat[k][0]
			if xr ^ mat[i][j - 1] != 0:
				res = [1] * i + [j] + [1] * (n - i - 1)
			else:
				res = [1] * i + [j + 1] + [1] * (n - i - 1)
			print('TAK')
			print(*res)
			return
xr = 0
for i in range(n):
	xr ^= mat[i][0]
if xr == 0:
	print('NIE')
else:
	print('TAK')
	res = [1] * n
	print(*res)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
for i in range(10):
	zero_flag = [False] * n
	one_flag = [False] * n
	for j in range(n):
		for k in range(m):
			if a[j][k] >> i & 1:
				one_flag[j] = True
			else:
				zero_flag[j] = True
	(zo, oo, bo) = (set(), set(), set())
	for j in range(n):
		if zero_flag[j] and one_flag[j]:
			bo.add(j)
		elif zero_flag[j]:
			zo.add(j)
		else:
			oo.add(j)
	ans = []
	if len(bo) == 0 and len(oo) % 2 == 1:
		for j in range(n):
			ans.append(1)
	elif len(bo) >= 1:
		if len(oo) % 2 == 0:
			for j in range(n):
				if j in zo or j in oo:
					ans.append(1)
				elif j == list(bo)[0]:
					for k in range(m):
						if a[j][k] >> i & 1:
							ans.append(k + 1)
							break
				else:
					for k in range(m):
						if not a[j][k] >> i & 1:
							ans.append(k + 1)
							break
		else:
			for j in range(n):
				if j in zo or j in oo:
					ans.append(1)
				else:
					for k in range(m):
						if not a[j][k] >> i & 1:
							ans.append(k + 1)
							break
	if len(ans) > 0:
		print('TAK')
		print(*ans)
		break
else:
	print('NIE')


(n, m) = tuple(map(int, input().strip().split()))
mat = []
for i in range(n):
	mmm = list(map(int, input().strip().split()))
	mat.append(mmm)
st = 0
rnum = -1
cnum = -1
for i in range(n):
	for ii in range(m - 1):
		if mat[i][ii] != mat[i][ii + 1]:
			st = 1
			rnum = i
			cnum = ii
			break
	if st == 1:
		break
if not st or m == 1:
	hh = 0
	sr = ''
	for i in range(n):
		hh = hh ^ mat[i][0]
		sr = sr + str(1) + ' '
	if hh == 0:
		print('NIE')
	else:
		print('TAK')
		print(sr)
else:
	print('TAK')
	sr = ''
	hh = 0
	for i in range(0, n):
		if i != rnum:
			hh = hh ^ mat[i][0]
	if hh ^ mat[rnum][cnum] == 0:
		for i in range(0, n):
			if i != rnum:
				sr = sr + str(1) + ' '
			else:
				sr = sr + str(cnum + 2) + ' '
	else:
		for i in range(0, n):
			if i != rnum:
				sr = sr + str(1) + ' '
			else:
				sr = sr + str(cnum + 1) + ' '
	print(sr)


(n, m) = map(int, input().split())
arr = [[int(x) for x in input().split()] for _ in range(n)]
(same, xor, same_cnt, diff) = ([], 0, 0, 0)
for (i, row) in enumerate(arr):
	xor ^= row[0]
	if sorted(row) == sorted(row, reverse=True):
		same.append(True)
		same_cnt += 1
	else:
		same.append(False)
		diff = i
if xor > 0:
	print('TAK')
	print('1 ' * n)
elif same_cnt == len(same):
	print('NIE')
else:
	print('TAK')
	print('1 ' * diff, end='')
	for i in range(m):
		if arr[diff][i] != arr[diff][0]:
			print(str(i + 1) + ' ', end='')
			break
	print('1 ' * (n - diff - 1))


def put():
	return map(int, input().split())
(n, m) = put()
l = []
xor = 0
for i in range(n):
	l.append(list(put()))
	xor ^= l[-1][0]
ans = [1] * n
if xor == 0:
	found = False
	for i in range(n):
		for j in range(1, m):
			if xor ^ l[i][0] ^ l[i][j] != 0:
				ans[i] = j + 1
				found = True
				xor = xor ^ l[i][0] ^ l[i][j]
				break
		if found:
			break
if xor == 0:
	print('NIE')
else:
	print('TAK')
	print(*ans)


import sys
(n, m) = map(int, input().split())
M = []
for i in range(n):
	M.append(list(map(int, input().split())))
result = 0
for i in range(n):
	result = result ^ M[i][0]
if result > 0:
	print('TAK')
	print(*[1 for _ in range(n)])
	return
is_solution_exist = False
row = None
col = None
for i in range(n):
	for j in range(m):
		if M[i][j] != M[i][0]:
			is_solution_exist = True
			row = i
			col = j
			break
	if is_solution_exist:
		break
if is_solution_exist:
	print('TAK')
	result = [1 for _ in range(n)]
	result[row] = col + 1
	print(*result)
else:
	print('NIE')


import sys
(n, m) = map(int, input().split())

def xor(A):
	x = 0
	for a in A:
		x ^= a
	return x
A = [[int(x) for x in input().split()] for _ in range(n)]
I = [0] * n
ref = A[0][0]
if xor((A[i][0] for i in range(n))):
	print('TAK')
	print(*[i + 1 for i in I])
	sys.exit()
else:
	for i in range(n):
		for j in range(m):
			if A[i][0] != A[i][j]:
				I[i] = j
				print('TAK')
				print(*[i + 1 for i in I])
				sys.exit()
print('NIE')


(n, m) = map(int, input().split())
arr = [[int(x) for x in input().split()] for _ in range(n)]
answer = []
for i in range(n):
	answer = [(i, 0)]
	for j in range(1, m):
		if arr[i][0] != arr[i][j]:
			answer.append((i, j))
			break
	if len(answer) > 1:
		break
if len(answer) > 1:
	print('TAK')
	for i in range(2):
		(a, b) = answer[i]
		temp = arr[a][b]
		for j in range(n):
			if a != j:
				temp = temp ^ arr[j][0]
		if temp:
			for j in range(n):
				if a != j:
					print(1, end=' ')
				else:
					print(b + 1, end=' ')
			break
else:
	temp = arr[0][0]
	for i in range(1, n):
		temp = temp ^ arr[i][0]
	if temp:
		print('TAK')
		for i in range(n):
			print(1, end=' ')
	else:
		print('NIE')


(n, m) = map(int, input().split())
arr1 = []
ans = 0
ansarr = [0] * n
for i in range(n):
	arr = list(map(int, input().split()))
	if arr.count(arr[0]) == len(arr):
		ans = ans ^ arr[0]
		ansarr[i] = 1
	else:
		arr1.append((arr, i))
for i in range(len(arr1)):
	for j in range(m):
		if ans ^ arr1[i][0][j] > 0:
			ans = ans ^ arr1[i][0][j]
			ansarr[arr1[i][1]] = j + 1
			break
if ans <= 0:
	print('NIE')
else:
	print('TAK')
	print(*ansarr)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
(rows, cols) = RMI()
matrix = [RMI() for _ in range(rows)]
ans = [0] * rows
xor = 0
for i in range(rows):
	xor ^= matrix[i][0]
for i in range(rows):
	if xor > 0:
		break
	for j in range(cols):
		curr = xor ^ matrix[i][0] ^ matrix[i][j]
		if curr > 0:
			ans[i] = j
			xor = curr
			break
if xor == 0:
	print('NIE')
else:
	print('TAK')
	print(*map(lambda x: x + 1, ans))


from collections import defaultdict as dd
import math

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return list(map(int, input().split()))

def lm():
	return list(map(int, input().split()))
(n, m) = mi()
matrix = []
for i in range(n):
	matrix.append(lm())
done = 0
good = -1
for i in range(n):
	val = matrix[i][0]
	for j in range(m):
		if not matrix[i][j] == val:
			good = (i, j)
			done = 1
			break
	if done == 1:
		break
start = 0
if good == -1:
	for i in range(n):
		start = start ^ matrix[i][0]
	if start == 0:
		print('NIE')
	else:
		print('TAK')
		out = ['1'] * n
		print(*out)
else:
	answers = []
	for i in range(n):
		start = start ^ matrix[i][0]
	if not start == 0:
		print('TAK')
		out = ['1'] * n
		print(*out)
	else:
		extra = 0
		for i in range(n):
			if not i == good[0]:
				extra = extra ^ matrix[i][0]
				answers.append('1')
			else:
				extra = extra ^ matrix[i][good[1]]
				answers.append(str(good[1] + 1))
		print('TAK')
		print(*answers)


(n, m) = map(int, input().split())
dont = 0
flagdont = True
arr = []
for i in range(n):
	arr.append(list(map(int, input().split())))
	for j in range(1, m):
		if arr[i][j] != arr[i][0]:
			flagdont = False
			dont = 0
			adadTaghir = i
			break
	else:
		if flagdont != False:
			dont = arr[i][0] ^ dont
	pass
if flagdont == True and dont == 0:
	print('NIE')
else:
	print('TAK')
	listJavab = []
	xor = 0
	for i in range(0, n):
		xor ^= arr[i][0]
		listJavab.append(1)
	if xor == 0:
		c = 1
		for i in range(1, m):
			if arr[adadTaghir][i] == arr[adadTaghir][0]:
				c += 1
			else:
				break
		listJavab[adadTaghir] = c + 1
	print(*listJavab)
	pass


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, m) = map(int, input().split())
	a = [list(map(int, input().split())) for _ in range(n)]
	xor = 0
	for i in a:
		xor ^= i[0]
	ans = [1] * n
	for i in range(n):
		for j in range(m):
			if xor ^ a[i][0] ^ a[i][j]:
				ans[i] = j + 1
				print('TAK')
				print(*ans)
				exit()
	print('NIE')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from time import time
from random import randint
from functools import reduce
from sys import exit
a = time()
(n, m) = map(int, input().split())
matrix = []
for i in range(n):
	matrix.append([int(x) for x in input().split()])
while time() - a < 0.8:
	xor = []
	ind = []
	for i in range(n):
		x = randint(0, m - 1)
		xor.append(matrix[i][x])
		ind.append(x + 1)
	if reduce(lambda x, y: x ^ y, xor):
		print('TAK')
		print(*ind)
		exit()
print('NIE')


(n, m) = list(map(int, input().split()))
arr = []
xor = 0
for i in range(n):
	d = list(map(int, input().split()))
	if i == 0:
		xor = d[0]
	else:
		xor ^= d[0]
	arr.append(d)
if xor != 0:
	print('TAK')
	print('1 ' * n)
else:
	ans = [1] * n
	fl = False
	for i in range(n):
		for g in range(1, m):
			if arr[i][g] != arr[i][0]:
				ans[i] = g + 1
				fl = True
				break
		if fl:
			break
	if fl:
		print('TAK')
		print(*ans)
	else:
		print('NIE')


(n, m) = map(int, input().split())
lis = [[int(j) for j in input().split()] for i in range(n)]
x = 0
y = 0
lis1 = []
for i in range(n):
	x = x ^ lis[i][0]
if x != 0:
	print('TAK')
	for i in range(n):
		print(1, end=' ')
else:
	for i in range(n):
		for j in range(1, m):
			if lis[i][j] != lis[i][0]:
				y = 1
				print('TAK')
				for z in lis1:
					print(z, end=' ')
				print(j + 1, end=' ')
				for k in range(n - i - 1):
					print(1, end=' ')
			if y == 1:
				break
		if y == 1:
			break
		else:
			lis1.append(1)
	if y == 0:
		print('NIE')


(m, n) = list(map(int, input().split()))
matrix = [list(map(int, input().split())) for i in range(m)]
c = 0
(x, y) = (0, 0)
dupa = 1
for i in range(m):
	if dupa == 0:
		break
	cur = matrix[i][0]
	for j in range(n):
		if matrix[i][j] != cur:
			x = i
			y = j
			print('TAK')
			c = 1
			dupa = 0
			break
import sys
if c == 0:
	zor = 0
	for i in range(m):
		zor = zor ^ matrix[i][0]
	if zor == 0:
		print('NIE')
		sys.exit(0)
	else:
		print('TAK')
		for k in range(m):
			print(1, end=' ')
		sys.exit(0)
else:
	for i in range(m):
		if i != x:
			print(1, end=' ')
		else:
			a = matrix[x][y]
			b = matrix[x][0]
			sor = 0
			for g in range(m):
				sor = sor ^ matrix[g][0]
			if sor > 0:
				print(0 + 1, end=' ')
			else:
				print(y + 1, end=' ')


(n, m) = map(int, input().split())
a = []
k = 0
ans = 0
for i in range(n):
	a.append(list(map(int, input().split())))
	ans ^= a[i][0]
	if len(set(a[i])) > len(set(a[k])):
		k = i
b = 0
for i in range(m):
	if ans ^ a[k][b] ^ a[k][i] != 0:
		ans ^= a[k][b] ^ a[k][i]
		b = i
if ans == 0:
	print('NIE')
else:
	print('TAK')
	for i in range(n):
		if i == k:
			print(b + 1, end=' ')
		else:
			print(1, end=' ')


import atexit
import io
import sys
sys.setrecursionlimit(123456)
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())
l = []

def btrack(m, r, cur, xor):
	global l
	if cur >= r:
		return xor > 0
	for i in set(m[cur]):
		xor ^= i
		if btrack(m, r, cur + 1, xor):
			l.append(i)
			return True
		xor ^= i
	return False

def main():
	global l
	(r, c) = map(int, input().split())
	m = []
	for _ in range(r):
		m.append(list(map(int, input().split())))
	if btrack(m, r, 0, 0):
		l = l[::-1]
		print('TAK')
		for i in range(r):
			print(m[i].index(l[i]) + 1, end=' ')
	else:
		print('NIE')
main()


from fractions import gcd
from collections import Counter

def main():
	(n, m) = [int(s) for s in input().split(' ')]
	res = 0
	res_array1 = []
	res_array2 = []
	found = False
	found_x = None
	found_y = None
	found_x_j = None
	found_y_j = None
	for i in range(n):
		A = [int(s) for s in input().split(' ')]
		c = Counter(A)
		B = list(c.items())
		if len(B) == 1:
			if found == False:
				res_array1.append(1)
				res ^= B[0][0]
			else:
				res_array2.append(1)
				res ^= B[0][0]
		elif found == False:
			found = True
			found_x = B[0][0]
			found_y = B[1][0]
			for j in range(m):
				if A[j] == found_x:
					found_x_j = j
				if A[j] == found_y:
					found_y_j = j
		else:
			res_array2.append(1)
			res ^= B[0][0]
	if found:
		if res ^ found_x > 0:
			res_array1.append(found_x_j + 1)
			res_array1.extend(res_array2)
		else:
			res_array1.append(found_y_j + 1)
			res_array1.extend(res_array2)
	elif res > 0:
		found = True
	if found:
		print('TAK')
		print(*res_array1)
	else:
		print('NIE')
main()


(n, m) = map(int, input().split())
l = []
for i in range(n):
	l += [list(map(int, input().split()))]
l1 = len(set(l[-1][:]))
s = []
for i in range(n):
	s += [set(l[i])]
save = -1
for i in range(n):
	if len(s[i]) > 1:
		save = i
		break
if save != -1:
	print('TAK')
	for j in range(m - 1):
		if l[save][j] != l[save][j + 1]:
			save1 = j
			break
	t = 0
	for i in range(n):
		if i != save:
			t = (t | l[i][0]) & (~t | ~l[i][0])
		else:
			t = (t | l[i][save1]) & (~t | ~l[i][j])
	if t != 0:
		for i in range(n):
			if i != save:
				print('1', end=' ')
			else:
				print(j + 1, end=' ')
	else:
		for i in range(n):
			if i != save:
				print('1', end=' ')
			else:
				print(j + 1 + 1, end=' ')
else:
	t = 0
	for i in range(n):
		t = (t | l[i][0]) & (~t | ~l[i][0])
	if t == 0:
		print('NIE')
		exit()
	print('TAK')
	for i in range(n):
		print('1', end=' ')


(n, m) = map(int, input().split())
a = [0] * 2 ** 10
b = []
t = 0
for i in range(n):
	temp = list(map(int, input().split()))
	b.append(temp)
	t = t ^ temp[0]
if t > 0:
	res = [1] * n
	print('TAK')
	print(*res)
	exit()
else:
	for i in range(n):
		for j in range(m):
			if b[i][j] != b[i][0]:
				res = [1] * i + [j + 1] + [1] * (n - i - 1)
				print('TAK')
				print(*res)
				exit()
print('NIE')


(n, m) = map(int, input().split())
(a, xor, b) = ([], 0, [1] * n)
for i in range(n):
	a.append(list(map(int, input().split())))
	xor = xor ^ a[i][0]
for i in range(n):
	for j in range(m):
		if xor ^ a[i][0] ^ a[i][j] != 0:
			b[i] = j + 1
			print('TAK')
			exit(print(*b))
print('NIE')


(n, m) = [int(x) for x in input('').split(' ')]
matlis = []
matset = []
leng = 1
swi = -1
for i in range(n):
	lis = [int(x) for x in input('').split(' ')]
	matlis.append(lis)
	matset.append(list(set(lis)))
	if len(set(lis)) > 1:
		leng = len(set(lis))
		swi = i
yihuo = matlis[0][0]
if swi < 0:
	for i in range(1, n):
		yihuo = yihuo ^ matlis[i][0]
	if yihuo == 0:
		print('NIE', end='')
	else:
		print('TAK')
		for i in range(n):
			print(1, end=' ')
else:
	print('TAK')
	if swi == 0:
		yihuo0 = matset[0][0]
		for i in range(1, n):
			yihuo0 = yihuo0 ^ matlis[i][0]
		if yihuo0 > 0:
			print(matlis[0].index(matset[0][0]) + 1, end=' ')
			for i in range(n - 1):
				print(1, end=' ')
		else:
			print(matlis[0].index(matset[0][1]) + 1, end=' ')
			for i in range(n - 1):
				print(1, end=' ')
	else:
		for i in range(1, n):
			if i != swi:
				yihuo = yihuo ^ matlis[i][0]
			else:
				yihuo = yihuo ^ matset[i][0]
		if yihuo > 0:
			for i in range(n):
				if i != swi:
					print(1, end=' ')
				else:
					print(matlis[swi].index(matset[swi][0]) + 1, end=' ')
		else:
			for i in range(n):
				if i != swi:
					print(1, end=' ')
				else:
					print(matlis[swi].index(matset[swi][1]) + 1, end=' ')


(n, m) = map(int, input().split())
l1 = []
l3 = []
for i in range(0, n):
	l2 = list(map(int, input().split()))
	l1.append(l2)
	l3.append(list(set(l2)))
ans = []
x = 0
for i in range(0, n):
	x = x ^ l3[i][0]
	ans.append(l3[i][0])
if x != 0:
	print('TAK')
	for i in range(0, n):
		print(l1[i].index(ans[i]) + 1, end=' ')
else:
	flag = 0
	for i in range(0, n):
		if len(l3[i]) != 1:
			ans[i] = l3[i][1]
			flag = 1
			break
	if flag == 0:
		print('NIE')
	else:
		print('TAK')
		for i in range(0, n):
			print(l1[i].index(ans[i]) + 1, end=' ')


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, OrderedDict
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
(n, m) = listIn()
mtx = []
ans = [1] * n
for i in range(n):
	a = listIn()
	mtx.append(a)
	if i == 0:
		x = mtx[0][0]
	else:
		x ^= mtx[i][0]
if m == 1:
	if x > 0:
		print('TAK')
		ans = [1] * n
		print(*ans)
	else:
		print('NIE')
	exit(0)
for i in range(n):
	if x > 0:
		break
	for j in range(m):
		if x ^ mtx[i][0] ^ mtx[i][j] > 0:
			ans[i] = j + 1
			x = mtx[i][0] ^ mtx[i][j]
			break
if x > 0:
	print('TAK')
	print(*ans)
else:
	print('NIE')


def solve():
	for k in range(10):
		(ft, tf, tt) = (0, 0, 0)
		for i in range(n):
			if l[i][k][0] and l[i][k][1]:
				tt += 1
			elif l[i][k][0]:
				tf += 1
			elif l[i][k][1]:
				ft += 1
		ans = []
		verdict = True
		if ft % 2 == 1:
			for i in range(n):
				if l[i][k][1] and (not l[i][k][0]):
					ans.append(ind[i][k][1])
				else:
					ans.append(ind[i][k][0])
		elif tt > 0:
			done_tt = False
			for i in range(n):
				if l[i][k][1] and (not l[i][k][0]):
					ans.append(ind[i][k][1])
				elif l[i][k][1] and l[i][k][0] and (not done_tt):
					ans.append(ind[i][k][1])
					done_tt = True
				else:
					ans.append(ind[i][k][0])
		else:
			verdict = False
		if verdict:
			return (verdict, ans)
	return (False, [])
(n, m) = [int(item) for item in input().split()]
g = []
for _ in range(n):
	g.append([int(item) for item in input().split()])
l = [[[False, False] for _ in range(10)] for i in range(n)]
ind = [[[1, 1] for _ in range(10)] for i in range(n)]
for i in range(n):
	for j in range(m):
		s = bin(g[i][j])[2:]
		for k in range(9, -1, -1):
			if k >= len(s):
				l[i][k][0] = True
				ind[i][k][0] = j + 1
				continue
			if not l[i][len(s) - k - 1][int(s[k])]:
				ind[i][len(s) - k - 1][int(s[k])] = j + 1
			l[i][len(s) - k - 1][int(s[k])] = True
res = solve()
if res[0]:
	print('TAK')
	print(*res[1])
else:
	print('NIE')


import sys
input = sys.stdin.readline
(N, M) = map(int, input().split())
state = [list(map(int, input().split())) for _ in range(N)]
ok = False
for b in range(10):
	L1 = [None] * N
	L0 = [None] * N
	for m in range(M):
		for n in range(N):
			if state[n][m] & 1 << b:
				L1[n] = m + 1
			else:
				L0[n] = m + 1
	must = 0
	leave = 0
	for n in range(N):
		if L0[n] is None:
			must += 1
		elif not L1[n] is None:
			leave += 1
	if leave > 0 or must % 2 == 1:
		leave += must
		ok = True
		L = []
		for n in range(N):
			if not L0[n] is None and (not L1[n] is None):
				if leave % 2 == 0:
					L.append(L0[n])
					leave -= 1
				else:
					L.append(L1[n])
			elif L0[n] is None:
				L.append(L1[n])
			else:
				L.append(L0[n])
		break
if ok:
	print('TAK')
	for l in L:
		print(l, end=' ')
	print()
else:
	print('NIE')


(x, y) = map(int, input().split())
p = list()
l = [1 for i in range(x)]
a = 0
for i in range(x):
	p.append(list(map(int, input().split())))
	a ^= p[i][0]
if a != 0:
	print('TAK')
	print('1 ' * x)
	exit()
else:
	for i in range(x):
		for j in range(y):
			if p[i][0] ^ p[i][j] != 0:
				print('TAK')
				l[i] += j
				print(*l)
				exit()
print('NIE')


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
b = []
ans = 0
for i in range(n):
	ans ^= a[i][0]
	b.append(1)
if ans != 0:
	print('TAK')
	for i in b:
		print(i, end=' ')
	print()
else:
	check = False
	for i in range(n):
		for j in range(m):
			if a[i][j] != a[i][0]:
				check = True
				b[i] = j + 1
				break
		if check:
			break
	if check:
		print('TAK')
		for i in b:
			print(i, end=' ')
		print()
	else:
		print('NIE')


def solve(s, n, depth, ans, curr):
	if depth == n:
		if curr != 0:
			return ans
		else:
			return []
	for i in s[depth]:
		xorr = curr ^ i
		ans.append(i)
		t = solve(s, n, depth + 1, ans, xorr)
		if t != []:
			return t
		ans.pop()
	return []
(n, m) = map(int, input().split())
arr = [list(map(int, input().split())) for i in range(n)]
s = [set() for i in range(1024)]
for i in range(n):
	for j in range(m):
		s[i].add(arr[i][j])
ans = []
ans = solve(s, n, 0, ans, 0)
if ans == []:
	print('NIE')
else:
	print('TAK')
	for i in range(len(ans)):
		print(arr[i].index(ans[i]) + 1, end=' ')
	print('')


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
res = [1] * n
isPossible = False
for i in range(n):
	cur = 0
	res = [1] * n
	for j in range(n):
		if i != j:
			cur = cur ^ a[j][0]
	for j in range(m):
		if cur ^ a[i][j] > 0:
			res[i] = j + 1
			isPossible = True
			break
	if isPossible:
		break
if isPossible:
	print('TAK')
	print(' '.join(map(str, res)))
else:
	print('NIE')


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n
primes = []

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	else:
		return int(input())
(n, m) = f(1)
mn = []
mx = []
mnind = []
mxind = []
cl = []
for i in range(n):
	t = f(2)
	ind = argsort(t)
	mnind.append(ind[0])
	mxind.append(ind[-1])
	mn.append(t[ind[0]])
	mx.append(t[ind[-1]])
	cl.append(t)
xor = 0
for x in mn:
	xor = xor ^ x
if xor == 0:
	st = False
	for i in range(n):
		if mn[i] != mx[i]:
			mnind[i] = mxind[i]
			st = True
			break
	if not st:
		print('NIE')
	else:
		print('TAK')
		print(*[x + 1 for x in mnind])
else:
	print('TAK')
	print(*[x + 1 for x in mnind])


from sys import stdin
import math
from copy import deepcopy
from collections import defaultdict

def find_xor(matrix, set_arr, bit):
	ans = []
	index = -1
	for i in range(len(set_arr)):
		(first, second) = set_arr[i]
		if first == True and second == True:
			index = i
			break
	if index != -1:
		xor = 0
		for i in range(len(matrix)):
			if i != index:
				xor ^= matrix[i][0]
				ans.append(1)
			else:
				ans.append(0)
		if xor & 2 ** bit == 0:
			for j in range(m):
				if matrix[index][j] & 2 ** bit != 0:
					ans[index] = j + 1
					return (xor ^ matrix[index][j], ans)
			else:
				ans[index] = 1
				return (xor ^ matrix[index][0], ans)
		else:
			for j in range(m):
				if matrix[index][j] & 2 ** bit == 0:
					ans[index] = j + 1
					return (xor ^ matrix[index][j], ans)
			else:
				ans[index] = 1
				return (xor ^ matrix[index][0], ans)
	else:
		xor = 0
		for i in range(len(matrix)):
			if i != index:
				xor ^= matrix[i][0]
				ans.append(1)
		return (xor, ans)

def check(set_arr):
	for i in set_arr:
		(first, second) = i
		if first == True and second == True:
			return True
	xor = 0
	for i in set_arr:
		(first, second) = i
		if first == True:
			xor ^= 0
		else:
			xor ^= 1
	if xor > 0:
		return True
	else:
		return False
(n, m) = list(map(int, stdin.readline().split()))
matrix = []
for _ in range(n):
	matrix.append(list(map(int, stdin.readline().split())))
set_arr = [[False, False] for x in range(n)]
for i in range(0, 10):
	num = 2 ** i
	set_arr = [[False, False] for x in range(n)]
	for j in range(n):
		for k in range(m):
			if num & matrix[j][k] == 0:
				set_arr[j][0] = True
			else:
				set_arr[j][1] = True
	if check(set_arr):
		(xor, ans) = find_xor(matrix, set_arr, i)
		print('TAK')
		print(*ans)
		exit()
else:
	print('NIE')


from sys import setcheckinterval, stdin, setrecursionlimit
setcheckinterval(1000)
setrecursionlimit(10 ** 7)

def iin():
	return int(stdin.readline())

def lin():
	return list(map(int, stdin.readline().split()))
(n, m) = lin()
a = [lin() for i in range(n)]
ans = [[set() for i in range(n + 1)] for j in range(10)]
for i in range(n):
	for j in range(m):
		x = a[i][j]
		xb = bin(x)[2:][::-1]
		for (k, val) in enumerate(xb):
			if val == '1':
				ans[k][i].add(j)
				ans[k][n].add(i)
for i in range(10):
	ln = len(ans[i][n])
	if ln:
		ch = 0
		if ln % 2 == 0:
			ch = 1
		comb = []
		for j in range(n):
			l1 = len(ans[i][j])
			if l1:
				for k in range(m):
					if ch:
						if k not in ans[i][j]:
							comb.append(k + 1)
							ch = 0
							break
					elif k in ans[i][j]:
						comb.append(k + 1)
						break
				else:
					comb.append(list(ans[i][j])[0] + 1)
			else:
				comb.append(1)
		xr = 0
		for idx in range(n):
			xr ^= a[idx][comb[idx] - 1]
		if xr:
			print('TAK')
			print(*comb)
			exit()
print('NIE')


s = input()
cuv = ''
for c in s:
	if c != ' ':
		cuv += c
	else:
		n = int(cuv)
		cuv = ''
m = int(cuv)
mat = [[]]
ok = False
row = 0
col = 0
for i in range(n):
	mat.append([])
	cnt = -1
	cuv = ''
	s = input()
	for c in s:
		if c != ' ':
			cuv += c
		else:
			mat[i].append(int(cuv))
			cuv = ''
			cnt += 1
			if mat[i][cnt] != mat[i][0]:
				row = i
				col = cnt
				ok = True
	mat[i].append(int(cuv))
	cnt += 1
	if mat[i][cnt] != mat[i][0]:
		row = i
		col = cnt
		ok = True
if ok:
	print('TAK\n')
	result1 = 0
	result2 = 0
	r1 = ''
	r2 = ''
	for i in range(n):
		result1 = result1 ^ mat[i][0]
		r1 += str(1) + ' '
		if i == row:
			result2 = result2 ^ mat[i][col]
			r2 += str(col + 1) + ' '
		else:
			result2 = result2 ^ mat[i][0]
			r2 += str(1) + ' '
	if result1 > 0:
		print(r1)
	else:
		print(r2)
else:
	result1 = 0
	r1 = ''
	for i in range(n):
		result1 = result1 ^ mat[i][0]
		r1 += str(1) + ' '
	if result1 > 0:
		print('TAK\n')
		print(r1)
	else:
		print('NIE')


import sys
input = sys.stdin.readline
(n, m) = list(map(int, input().strip().split()))
mat = []
for i in range(n):
	mat.append(list(map(int, input().strip().split())))
se = set()
for x in mat:
	for y in x:
		se.add(y)
if n == 1:
	val = False
	ans = None
	for x in range(m):
		if mat[0][x] != 0:
			ans = x + 1
			val = True
			break
	if val:
		print('TAK')
		print(ans)
	else:
		print('NIE')
elif len(se) == 1:
	print('NIE')
else:
	ans = set()
	an = []
	for i in range(n):
		if len(ans) < 2:
			found = False
			for j in range(m):
				if mat[i][j] not in ans:
					found = True
					ans.add(mat[i][j])
					an.append(j + 1)
					break
			if not found:
				ans.add(mat[i][0])
				an.append(1)
		else:
			an.append(1)
	xr = 0
	for i in range(n):
		xr ^= mat[i][an[i] - 1]
	if xr != 0:
		print('TAK')
		print(' '.join(map(str, an)))
	else:
		ex = False
		for i in range(n):
			cur = an[i]
			for j in range(m):
				if j != cur - 1:
					if ex ^ mat[i][cur - 1] ^ mat[i][j] != 0:
						an[i] = j + 1
						ex = True
						break
			if ex:
				break
		if ex:
			print('TAK')
			print(' '.join(map(str, an)))
		else:
			print('NIE')


(n, m) = [int(i) for i in input().split()]
a = 0
store = []
for i in range(n):
	temp = [int(j) for j in input().split()]
	store.append(temp)
	a ^= temp[0]
if a > 0:
	print('TAK')
	for i in range(n):
		print(1, end=' ')
else:
	flag = 0
	ii = -1
	jj = -1
	for i in range(n):
		for j in range(m):
			if store[i][j] != store[i][0]:
				ii = i
				jj = j
				flag = 1
				break
	if flag == 0:
		print('NIE')
	else:
		print('TAK')
		for i in range(n):
			if i != ii:
				print(1, end=' ')
			else:
				print(jj + 1, end=' ')


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	max_so_far = -sys.maxsize - 1
	max_ending_here = 0
	start = 0
	end = 0
	s = 0
	for i in range(0, size):
		max_ending_here += a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
			start = s
			end = i
		if max_ending_here < 0:
			max_ending_here = 0
			s = i + 1
	return (max_so_far, start, end)

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] >= arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def solve():
	(n, m) = num_input()
	mat = []
	ans = [1] * n
	flag = False
	x = 0
	for i in range(n):
		mat.append(list_input())
		x ^= mat[i][0]
	if x != 0:
		print('TAK')
		print(*ans)
	else:
		indx = -1
		row = 0
		for M in mat:
			for i in range(m):
				if M[0] != M[i]:
					indx = i
					flag = True
					break
			if flag:
				break
			row += 1
		if flag:
			print('TAK')
			ans[row] = indx + 1
			print(*ans)
		else:
			print('NIE')
t = 1
for _ in range(t):
	solve()


line = list(map(int, input().split()))
n = line[0]
m = line[1]
a = [None] * n
sXor = 0
for i in range(n):
	a[i] = list(map(int, input().split()))
	sXor ^= a[i][0]
sol = [1] * n
if sXor != 0:
	print('TAK')
	for i in range(n):
		print(str(sol[i]), end=' ')
else:
	solved = False
	for i in range(n):
		for j in range(1, m):
			if a[i][j] != a[i][0]:
				sol[i] = j + 1
				solved = True
				break
		if solved:
			break
	if solved:
		print('TAK')
		for i in range(n):
			print(str(sol[i]), end=' ')
	else:
		print('NIE')


(n, m) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
xox = 0
s = 0
F = 0
for i in range(n):
	M = A[i]
	if not F and len(set(M)) != 1:
		s = i
		F = 1
	else:
		xox ^= M[0]
if F:
	ans = [1] * n
	for i in range(m):
		if A[s][i] != xox:
			ans[s] = i + 1
	print('TAK')
	print(' '.join(list(map(str, ans))))
elif xox == 0:
	print('NIE')
else:
	print('TAK')
	print('1 ' * n)


import sys
(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
x = 0
for r in a:
	x ^= r[0]
ans = [1] * n
for i in range(n):
	for j in range(m):
		if x ^ a[i][0] ^ a[i][j]:
			ans[i] = j + 1
			print('TAK')
			print(*ans)
			sys.exit(0)
print('NIE')


(col, row) = [int(i) for i in input().split()]
array = list()
for i in range(col):
	array.append([int(i) for i in input().split()])
choice = list()
xor = int()
for i in range(col):
	choice.append(str(1))
	xor = xor ^ array[i][0]
if xor == 0:
	for i in range(col):
		current = array[i][0]
		check = False
		for j in range(row):
			if array[i][j] != current:
				choice[i] = str(j + 1)
				print('TAK')
				print(' '.join(choice))
				check = True
				break
		if check:
			break
	if check == False:
		print('NIE')
else:
	print('TAK')
	print(' '.join(choice))


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')

def xor(nums):
	x = 0
	for i in nums:
		x ^= i
	return x
(n, m) = int_array()
a = []
for _ in range(n):
	a.append(int_array())
ans = [0] * n
nums = [None] * n
for i in range(n):
	nums[i] = a[i][ans[i]]
if xor(nums) != 0:
	for i in range(n):
		ans[i] += 1
	print('TAK')
	print(*ans)
	exit()
f = 0
for i in range(n):
	if f:
		break
	x = a[i][0]
	for j in range(1, m):
		if a[i][j] != x:
			f = 1
			ans[i] = j
			break
if f:
	for i in range(n):
		ans[i] += 1
	print('TAK')
	print(*ans)
else:
	print('NIE')


(n, m) = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for _ in range(n)]

def test(a, n, m):
	for i in range(n):
		(_or, _and) = (a[i][0], a[i][0])
		for j in range(m):
			_or |= a[i][j]
			_and &= a[i][j]
		if _or != _and:
			return i
	return -1
t = test(a, n, m)
if t == -1:
	_xor = 0
	for i in range(n):
		_xor ^= a[i][0]
	if _xor > 0:
		print('TAK')
		print(' '.join(('1' for _ in range(n))))
		exit()
else:
	_xor = 0
	for i in range(n):
		if i == t:
			continue
		_xor ^= a[i][0]
	for j in range(m):
		if _xor ^ a[t][j] > 0:
			print('TAK')
			print(' '.join(['1' if k != t else str(j + 1) for k in range(n)]))
			exit()
print('NIE')


(n, m) = [int(i) for i in input().split()]
a = 0
b = -1
l1 = []
l2 = []
for i in range(n):
	s = [int(i) for i in input().split()]
	if b != -1:
		l1.append(1)
		a ^= s[0]
		b ^= s[0]
		l2.append(1)
	else:
		f = set(s)
		if len(f) == 1:
			l1.append(1)
			l2.append(1)
			a ^= s[0]
		else:
			b = a
			g = list(f)
			b ^= g[0]
			a ^= g[1]
			l1.append(1 + s.index(g[0]))
			l2.append(1 + s.index(g[1]))
if b == -1:
	if a:
		print('TAK')
		print(*l2)
	else:
		print('NIE')
else:
	print('TAK')
	if a:
		print(*l2)
	else:
		print(*l1)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
fl = -1
k = 0
for i in range(n):
	if len(set(a[i])) > 1:
		fl = i
		break
x = a[0][0]
for i in range(n):
	for j in range(m):
		if a[i][j] != x:
			k = 1
			break
if k == 0 and n % 2 == 0 or (k == 0 and a[0][0] == 0):
	exit(print('NIE'))
else:
	ans = [1] * n
	x = 0
	if fl != -1:
		for i in range(n):
			if i != fl:
				x ^= a[i][0]
		for i in range(m):
			if x ^ a[fl][i] > 0:
				ans[fl] = i + 1
				break
	x = 0
	for i in range(n):
		x ^= a[i][ans[i] - 1]
	if x > 0:
		print('TAK')
		print(*ans)
	else:
		print('NIE')


(n, l) = input().split()
n = int(n)
l = int(l)
matriz = [0] * n
resposta = 0
for i in range(0, n):
	linha = input().split()
	matriz[i] = linha
	resposta = int(matriz[i][0]) ^ resposta
if resposta > 0:
	print('TAK', end='\n')
	for i in range(0, n):
		print('1 ')
else:
	linha = -1
	coluna = -1
	for i in range(0, n):
		for j in range(1, l):
			if matriz[i][j] != matriz[i][0]:
				linha = i
				coluna = j
	if linha == -1:
		print('NIE')
	else:
		print('TAK', end='\n')
		for i in range(0, n):
			if i == linha:
				print(str(coluna + 1) + ' ', end='')
			else:
				print('1 ', end='')


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
flag = False
for sft in range(10):
	b = [[a[i][j] >> sft & 1 for j in range(m)] for i in range(n)]
	must1 = 0
	must0 = 0
	for i in range(n):
		for j in range(m):
			if b[i][j] == 0:
				break
		else:
			must1 += 1
	for i in range(n):
		for j in range(m):
			if b[i][j] == 1:
				break
		else:
			must0 += 1
	if must1 == n and n % 2 == 1:
		c = [1 for i in range(n)]
		print('TAK')
		print(*c)
		exit()
	elif must1 == n and n % 2 == 0:
		continue
	elif must0 == n:
		continue
	elif must1 < n and must0 < n:
		if must1 % 2 == 1:
			c = []
			for i in range(n):
				flag = True
				idx = -1
				for j in range(m):
					if b[i][j] == 0:
						flag = False
						idx = j
				if flag:
					c.append(1)
				else:
					c.append(idx + 1)
			print('TAK')
			print(*c)
			exit()
		elif must1 + must0 != n:
			c = []
			flag2 = True
			for i in range(n):
				flag = True
				idx = -1
				z = -1
				for j in range(m):
					if b[i][j] == 0:
						flag = False
						idx = j
					elif z == -1:
						z = j
				if flag:
					c.append(1)
				elif z >= 0 and flag2:
					c.append(z + 1)
					flag2 = False
				else:
					c.append(idx + 1)
			print('TAK')
			print(*c)
			exit()
print('NIE')


(n, m) = list(map(int, input().split(' ')))
mat = [None for i in range(n)]
for i in range(n):
	mat[i] = list(map(int, input().split(' ')))
tmp_xor = 0
for i in range(n):
	tmp_xor ^= mat[i][0]
if tmp_xor:
	print('TAK')
	for i in range(n):
		print('1 ', end='')
else:
	flag = False
	idx = 0
	val = 0
	for i in range(n):
		for j in range(m):
			if mat[i][j] != mat[i][0]:
				flag = True
				idx = i
				val = j
				break
		if flag:
			break
	if flag:
		print('TAK')
		for i in range(idx):
			print('1', end=' ')
		print(val + 1, end=' ')
		for i in range(idx + 1, n, 1):
			print('1', end=' ')
	else:
		print('NIE')


(n, m) = map(int, input().split())
matrix = []
for i in range(n):
	matrix.append(list(map(int, input().split())))
for list in matrix:
	if len(set(list)) != 1:
		break
else:
	xor = 0
	for list in matrix:
		xor ^= list[0]
	if xor == 0:
		print('NIE')
		exit()
print('TAK')
ls = []
matrix.reverse()
for i in range(n):
	if len(set(matrix[i])) != 1:
		break
index = n - 1 - i
matrix.reverse()
xor = 0
for i in range(n):
	if i != index:
		xor ^= matrix[i][0]
for i in range(n):
	if i != index:
		ls.append(1)
	else:
		for j in range(m):
			if matrix[i][j] != xor:
				ls.append(j + 1)
				break
for i in ls:
	print(i, end=' ')


(n, m) = map(int, input().split())
output = [1] * n
Xor = 0
lis = []
for i in range(n):
	lis2 = list(map(int, input().split()))
	Xor = Xor ^ lis2[0]
	lis.append(lis2)
if Xor != 0:
	print('TAK')
	for i in output:
		print(i, end=' ')
	exit()
for i in range(n):
	element = lis[i][0]
	for j in range(1, m):
		if lis[i][j] != element:
			output[i] = j + 1
			print('TAK')
			for i in output:
				print(i, end=' ')
			exit()
print('NIE')


mat = []
(n, m) = [int(i) for i in input().split()]
xor = 0
res = []
flag = False
for i in range(n):
	mat.append([int(i) for i in input().split()])
	xor = xor ^ mat[len(mat) - 1][0]
	res.append(1)
if xor > 0:
	flag = True
else:
	for i in range(n):
		for j in range(1, m):
			if mat[i][res[i] - 1] != mat[i][j]:
				res[i] = j + 1
				flag = True
				break
		if flag:
			break
if not flag:
	print('NIE')
else:
	print('TAK')
	print(' '.join([str(i) for i in res]))


(n, m) = [int(i) for i in input().split()]
l = [[] for i in range(n)]
for i in range(n):
	l[i] = [int(j) for j in input().split()]
l1 = []
for i in range(n):
	l1.append(l[i][0])
xv = 0
for i in range(n):
	xv = xv ^ l1[i]
if xv > 0:
	print('TAK')
	for k in range(n):
		print(1, end=' ')
	exit(0)
t1 = 0
t2 = 0
for i in range(n):
	t1 = xv
	t1 = t1 ^ l[i][0]
	for j in range(m):
		t2 = t1
		t2 = t2 ^ l[i][j]
		if t2 > 0:
			print('TAK')
			for k in range(n):
				if i == k:
					print(j + 1, end=' ')
				else:
					print(1, end=' ')
			exit(0)
print('NIE')


(n, m) = map(int, input().split())
arr = [[] for _ in range(n)]
ans = [-1] * n
for i in range(n):
	vis = set()
	for (j, c) in enumerate(list(map(int, input().split()))):
		if c not in vis:
			arr[i].append([c, i, j + 1])
			vis.add(c)
arr.sort(key=lambda x: len(x))

def dfs(cur, p):
	if cur == n:
		if p > 0:
			return True
		return False
	for (v, row, col) in arr[cur]:
		ans[row] = col
		if dfs(cur + 1, p ^ v):
			return True
		ans[row] = -1
	return False
if dfs(0, 0):
	print('TAK')
	print(*ans)
else:
	print('NIE')


(n, m) = map(int, input().split())
g = []
r_mult = -1
for i in range(n):
	r = [int(s) for s in input().split()]
	dist = {}
	for (j, v) in enumerate(r):
		if v not in dist:
			dist[v] = j + 1
	r = [(v, dist[v]) for v in dist]
	if len(r) > 1 and r_mult == -1:
		r_mult = i
	g.append(r)
sum0 = 0
has_ans = False
for i in range(n):
	sum0 ^= g[i][0][0]
if sum0 > 0 or r_mult != -1:
	has_ans = True
if has_ans:
	ans = []
	for i in range(n):
		to_app = g[i][0][1]
		if sum0 == 0 and r_mult != -1 and (i == r_mult):
			to_app = g[i][1][1]
		ans.append(to_app)
	print('TAK')
	print(*ans)
else:
	print('NIE')


def main():
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	xor = 0
	for i in range(n):
		xor ^= l[i][0]
	pos = [0] * n
	if xor == 0:
		for i in range(n):
			for j in range(m):
				if l[i][j] != l[i][0]:
					pos[i] = j
					print('TAK' + '\n' + ' '.join([str(ch + 1) for ch in pos]))
					return
	if xor == 0:
		print('NIE')
	else:
		print('TAK' + '\n' + ' '.join([str(ch + 1) for ch in pos]))
main()


(n, _) = map(int, input().split())
mtrx = [list(map(int, input().split())) for _ in range(n)]
dri = None
for (i, row) in enumerate(mtrx):
	if len(set(row)) > 1:
		dri = i
		break
if dri is None:
	rez = 0
	for row in mtrx:
		rez ^= row[0]
	if rez:
		print('TAK')
		print(*[1] * n)
	else:
		print('NIE')
	exit(0)
rez = 0
rarr = []
for (i, row) in enumerate(mtrx):
	if i == dri:
		rarr.append(None)
	else:
		rez ^= row[0]
		rarr.append(1)
for (i, v) in enumerate(mtrx[dri]):
	if v ^ rez:
		rarr[dri] = i + 1
		break
print('TAK')
print(*rarr)


def taknie(n, m):
	v = [0]
	for i in range(n):
		l = [int(x) for x in input().split()]
		l.insert(0, 0)
		v.append(l)
	resp = 0
	for i in range(1, n + 1):
		resp ^= v[i][1]
	if resp:
		print('TAK')
		for i in range(1, n + 1):
			print('1')
	else:
		for i in range(1, n + 1):
			for j in range(2, m + 1):
				if v[i][j] != v[i][1]:
					print('TAK')
					for k in range(1, n + 1):
						if k != i:
							print('1')
						else:
							print(j)
					return
		print('NIE')
arr = [int(x) for x in input().split()]
n = arr[0]
m = arr[1]
taknie(n, m)


(n, m) = map(int, input().split())
alt_i = 0
alt = 0
res = []
srt = True
xr = 0
for _ in range(n):
	inp = {}
	j = 1
	for inp1 in map(int, input().split()):
		inp[inp1] = j
		j += 1
	inp1 = next(iter(inp.keys()))
	res.append(inp[inp1])
	del inp[inp1]
	xr ^= inp1
	if srt:
		if inp:
			alt = inp[next(iter(inp.keys()))]
			srt = False
		else:
			alt_i += 1
if not (srt or xr):
	res[alt_i] = alt
	xr = 1
if xr:
	print('TAK')
	print(*res)
else:
	print('NIE')


(n, m) = map(int, input().split())
a = []
idx = -1
for _ in range(n):
	z = list(map(int, input().split()))
	s = set(z)
	if len(set(s)) > 1:
		idx = _
		p = sorted(set(s))
		(jdx, kdx) = (z.index(p[0]), z.index(p[-1]))
	a.append(z)
res = 0
if idx == -1:
	for i in range(n):
		res ^= a[i][0]
	if res:
		print('TAK')
		print(*[1] * n)
	else:
		print('NIE')
else:
	print('TAK')
	for i in range(n):
		if i != idx:
			res ^= a[i][0]
	if res ^ a[idx][jdx]:
		print(*[1] * idx + [jdx + 1] + [1] * (n - idx - 1))
	else:
		print(*[1] * idx + [kdx + 1] + [1] * (n - idx - 1))


__version__ = '1.3'
__date__ = '2019-04-18'
import sys

def find_xor(matrix, m, n):
	idx = [list(range(1024)) for r in range(m)]
	xors = [set() for r in range(m)]
	for (col, val) in enumerate(matrix[0]):
		idx[0][val] = [col]
	xors[0] = set(matrix[0])
	for row in range(1, m):
		for col in range(n):
			if len(xors[row]) > 1:
				break
			for xor in xors[row - 1]:
				if len(xors[row]) > 1:
					break
				val = xor ^ matrix[row][col]
				if val not in xors[row]:
					xors[row].add(val)
					idx[row][val] = idx[row - 1][xor] + [col]
	xors[-1].add(0)
	if len(xors[-1]) > 1:
		xor = sorted(xors[-1])[1]
		return [col + 1 for col in idx[-1][xor]]
	return []

def main(argv=None):
	(m, n) = list(map(int, input().split()))
	matrix = [list(map(int, input().split())) for row in range(m)]
	route = find_xor(matrix, m, n)
	if not route:
		print('NIE')
	else:
		print('TAK')
		print(' '.join(map(str, route)))
	return 0
STATUS = main()
sys.exit(STATUS)


from sys import stdin
inp = lambda : stdin.readline().strip()
(n, m) = [int(x) for x in inp().split()]
a = [[] for x in range(n)]
b = [set() for x in range(n)]
flag = False
inPair = []
for i in range(n):
	count = 1
	for j in inp().split():
		a[i].append(int(j))
		b[i].add(int(j))
		if len(b[i]) > 1:
			flag = True
			inPair.append(i)
			inPair.append(count)
		count += 1
xor = a[0][0]
for i in range(1, n):
	xor ^= a[i][0]
if xor > 0:
	print('TAK')
	print('1 ' * n)
elif flag:
	print('TAK')
	for i in range(n):
		if i == inPair[0]:
			print(inPair[1], end=' ')
		else:
			print(1, end=' ')
else:
	print('NIE')


x = input().split()
n = int(x[0])
m = int(x[1])
can = 0
lines = []
for i in range(n):
	lines.append(input().split())
for i in range(n):
	l = set(lines[i])
	if len(l) > 1:
		can = 1
		break
result = 0
first_zero = 0
for i in range(n):
	result = result ^ int(lines[i][0])
if result == 0:
	first_zero = 1
if can == 0:
	if first_zero == 1:
		print('NIE')
	else:
		print('TAK')
		x = ''
		for i in range(n - 1):
			x = x + '1' + ' '
		x += '1'
		print(x)
else:
	print('TAK')
	if first_zero == 0:
		x = ''
		for i in range(n - 1):
			x = x + '1' + ' '
		x += '1'
		print(x)
	else:
		alright = 0
		x = ''
		for i in range(n):
			for j in range(m - 1):
				if lines[i][j] != lines[i][j + 1]:
					x += str(j + 2) + ' '
					alright = 1
					break
			if alright == 1:
				for j in range(n - i - 1):
					x += '1 '
				break
			else:
				x += '1' + ' '
		print(x[:len(x) - 1])


import collections
(m, n) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(m)]
b = a[0][0]
ans = [1] * m
for i in range(1, m):
	b = b ^ a[i][0]
for i in range(m):
	for j in range(n):
		if b ^ a[i][0] ^ a[i][j] != 0:
			ans[i] = j + 1
			print('TAK')
			exit(print(*ans))
			break
print('NIE')


import sys
input = sys.stdin.readline
from collections import defaultdict
(n, m) = map(int, input().split())
matrix = []
for i in range(n):
	matrix.append(list(map(int, input().split())))
ans = []
dp = [[-1] * 1024 for i in range(501)]

def sol(i, val):
	if dp[i][val] != -1:
		return dp[i][val]
	if i == n - 1:
		for j in range(m):
			ans.append(j + 1)
			if val ^ matrix[i][j] > 0:
				dp[i][val] = True
				return True
			ans.pop()
		dp[i][val] = False
		return False
	for j in range(m):
		ans.append(j + 1)
		if sol(i + 1, val ^ matrix[i][j]):
			dp[i][val] = True
			return True
		ans.pop()
	dp[i][val] = False
	return False
if sol(0, 0):
	print('TAK')
	print(*ans)
else:
	print('NIE')


def fun():
	(n, m) = (int(x) for x in input().split())
	matrix = []
	answer = 0
	for i in range(n):
		line = [int(x) for x in input().split()]
		answer ^= line[0]
		matrix.append(line)
	if answer > 0:
		print('TAK')
		values = n * [1]
		print(*values)
		return
	else:
		for i in range(n):
			j = 1
			while j < m:
				if matrix[i][j] != matrix[i][0]:
					print('TAK')
					values = []
					for k in range(n):
						if k != i:
							values.append(1)
						else:
							values.append(j + 1)
					print(*values)
					return
				j += 1
		print('NIE')
fun()


(n, m) = list(map(int, input().split()))
res = 0
pair = None
row = -1
column = -1
for i in range(n):
	tmp = list(map(int, input().split()))
	if pair is None:
		has_pair = False
		for j in range(len(tmp) - 1):
			if tmp[j] != tmp[j + 1]:
				has_pair = True
				pair = (tmp[j], tmp[j + 1])
				row = i
				column = j
				break
		if not has_pair:
			res ^= tmp[0]
	else:
		res ^= tmp[0]
if pair is None and res == 0:
	print('NIE')
else:
	selection = [1] * n
	if pair is not None:
		if pair[0] != res:
			selection[row] = column + 1
		else:
			selection[row] = column + 2
	print('TAK')
	print(' '.join(list(map(str, selection))))


(n, m) = map(int, input().split())
grid = []
for i in range(n):
	grid.append(list(map(int, input().split())))
xor = 0
for i in range(n):
	xor ^= grid[i][0]

def find(grid):
	for i in range(n):
		for j in range(1, m):
			if grid[i][j] != grid[i][0]:
				return (i, j)
	return (-1, -1)
if xor == 0:
	(a, b) = find(grid)
	if a == b == -1:
		print('NIE')
	else:
		print('TAK')
		for i in range(n):
			if i == a:
				print(b + 1, end=' ')
			else:
				print(1, end=' ')
else:
	print('TAK')
	print(*[1] * n)


arr = input()
(row, col) = [int(x) for x in arr.split(' ')]
data = [[0] * col for _ in range(row)]
for i in range(row):
	arr = input()
	arr = [int(x) for x in arr.split(' ')]
	for j in range(col):
		data[i][j] = arr[j]
res = 0
ans = [1] * row
for i in range(row):
	res = res ^ data[i][0]
flag = 0
if res == 0:
	for i in range(row):
		for j in range(1, col):
			if data[i][j] != data[i][0]:
				flag = 1
				ans[i] = j + 1
				break
		if flag == 1:
			break
else:
	flag = 1
if flag == 1:
	print('TAK')
	for num in ans:
		print(num, end=' ')
else:
	print('NIE')


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
import random

def solve():
	(n, m) = aj()
	A = []
	B = []
	for i in range(n):
		a = aj()
		A.append(a)
		B.append(list(set(a)))
	flag = False
	for i in range(1000):
		Ans = []
		p = 0
		for i in range(n):
			if len(B[i]) == 1:
				p ^= B[i][0]
				Ans.append(B[i][0])
			else:
				num = random.choice(B[i])
				p ^= num
				Ans.append(num)
		if p > 0:
			flag = True
			break
	if not flag:
		print('NIE')
		exit(0)
	print('TAK')
	Z = []
	for i in range(n):
		Z.append(A[i].index(Ans[i]) + 1)
	print(*Z)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


def main():
	(n, m) = map(int, input().split())
	grid = [list(map(int, input().split())) for i in range(n)]
	flag = 0
	mi = [0] * n
	ma = [0] * n
	for i in range(n):
		mi[i] = min(grid[i])
		ma[i] = max(grid[i])
		if mi[i] != ma[i]:
			flag = i + 1
	if flag:
		print('TAK')
		ans = [1] * n
		xor = 0
		for i in range(flag - 1):
			xor ^= grid[i][0]
		for i in range(flag, n):
			xor ^= grid[i][0]
		if xor ^ mi[flag - 1]:
			ans[flag - 1] = grid[flag - 1].index(mi[flag - 1]) + 1
		else:
			ans[flag - 1] = grid[flag - 1].index(ma[flag - 1]) + 1
		print(*ans)
	else:
		ans = [1] * n
		xor = 0
		for i in range(n):
			xor ^= grid[i][0]
		if xor:
			print('TAK')
			print(*ans)
		else:
			print('NIE')
	return 0
main()


import sys
input = sys.stdin.readline
for _ in range(1):
	(n, m) = map(int, input().split())
	mat = []
	available = [0] * 11
	filled = [0] * 11
	sep = [0] * 11
	for i in range(n):
		l = list(map(int, input().split()))
		mat.append(l)
		cnt = [0] * 11
		for x in l:
			w = bin(x)[2:][::-1]
			for e in range(len(w)):
				if w[e] == '1':
					available[e] = 1
					cnt[e] += 1
		for r in range(len(cnt)):
			w = cnt[r]
			if w == m:
				filled[r] += 1
				continue
			if w > 0:
				sep[r] = 1
	flag = 0
	ans = []
	for i in range(len(available)):
		x = available[i]
		if x == 0:
			continue
		if filled[i] % 2 == 0 and sep[i] == 0:
			continue
		if filled[i] == 0:
			v = 0
			for r in range(n):
				z = 0
				q = 0
				for c in range(m):
					g = mat[r][c]
					w = bin(g)[2:]
					toadd = 11 - len(w)
					w = '0' * toadd + w
					w = w[::-1]
					if w[i] == '0':
						z = c + 1
					else:
						q = c + 1
				if v == 0 and q != 0:
					v = 1
					ans.append(q)
				else:
					ans.append(z)
			flag = 1
			break
		if filled[i] % 2 == 1:
			for r in range(n):
				f = 1
				z = 0
				for c in range(m):
					g = mat[r][c]
					w = bin(g)[2:]
					toadd = 11 - len(w)
					w = '0' * toadd + w
					w = w[::-1]
					if w[i] == '0':
						f = 0
						z = c + 1
				if f == 1:
					ans.append(1)
				else:
					ans.append(z)
		else:
			v = 0
			for r in range(n):
				f = 1
				z = 0
				q = 0
				for c in range(m):
					g = mat[r][c]
					w = bin(g)[2:]
					toadd = 11 - len(w)
					w = '0' * toadd + w
					w = w[::-1]
					if w[i] == '0':
						f = 0
						z = c + 1
					else:
						q = c + 1
				if f == 1:
					ans.append(1)
				elif v == 0 and q != 0:
					v = 1
					ans.append(q)
				else:
					ans.append(z)
		flag = 1
		break
	if flag == 0:
		print('NIE')
	else:
		print('TAK')
		print(*ans)


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
x = 0
for i in range(n):
	x ^= a[i][0]
ans = [1] * n
for i in range(n):
	if len(set(a[i])) > 1:
		for j in range(m):
			if x ^ a[i][0] ^ a[i][j]:
				ans[i] = j + 1
		print('TAK')
		print(*ans)
		break
else:
	if x:
		print('TAK')
		print(*ans)
	else:
		print('NIE')


import sys
(n, m) = list(map(int, sys.stdin.readline().strip().split()))
L = [0] * n
ans = 0
for i in range(0, n):
	row = list(map(int, sys.stdin.readline().strip().split()))
	j = row[0]
	l = -1
	for k in range(0, m):
		if row[k] != j:
			l = k
	L[i] = l
	ans = ans ^ j
if ans != 0:
	print('TAK')
	print(('1 ' * n).strip())
elif max(L) == -1:
	print('NIE')
else:
	for i in range(0, n):
		if L[i] != -1:
			j = i
	print('TAK')
	print('1 ' * j + str(L[j] + 1) + (n - j - 1) * ' 1')


(n, m) = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(n)]
flag = 0
for i in range(n):
	if len(set(s[i])) != 1:
		flag = 1
		break
if flag == 0:
	a = 0
	for j in range(n):
		a = a ^ s[j][0]
	if a == 0:
		print('NIE')
		exit()
	else:
		print('TAK')
		print(' '.join(['1' for i in range(n)]))
		exit()
if flag == 1:
	a = s[i][0]
	for j in range(m):
		if s[i][j] != a:
			b = s[i][j]
			break
	(x, y) = (0, 0)
	for t in range(n):
		x = x ^ s[t][0]
		if t == i:
			y = y ^ s[t][j]
		else:
			y = y ^ s[t][0]
	print('TAK')
	if x != 0:
		print(' '.join(['1' for i in range(n)]))
	else:
		s = ['1' for i in range(n)]
		s[i] = str(j + 1)
		print(' '.join(s))


import math
from collections import defaultdict
import sys

def main():
	(n, m) = map(int, input().split())
	a = [[] for _ in range(n)]
	for row in range(n):
		a[row] = list(map(int, input().split()))
	x = 0
	for row in range(n):
		x ^= a[row][0]
	if x > 0:
		print('TAK')
		print(*[1 for _ in range(n)])
	else:
		res = [1 for _ in range(n)]
		ok = False
		for r in range(n):
			for c in range(1, m):
				x ^= a[r][c - 1]
				x ^= a[r][c]
				res[r] = c + 1
				if x > 0:
					ok = True
					break
			if ok:
				break
		if ok:
			print('TAK')
			print(*res)
		else:
			print('NIE')
main()


import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
ans = [1] * n
res = 0
for i in range(n):
	res ^= a[i][0]
if res != 0:
	print('TAK')
	print(*ans)
	exit()
for i in range(n):
	res ^= a[i][0]
	for j in range(m):
		res ^= a[i][j]
		if res != 0:
			ans[i] = j + 1
			print('TAK')
			print(*ans)
			exit()
		res ^= a[i][j]
	res ^= a[i][0]
print('NIE')


(n, m) = map(int, input().split())
mat = []
lis = []
ans = []
k = 0
cur = 0
for i in range(n):
	temp = list(map(int, input().split()))
	mat.append(temp)
for i in range(n):
	cur ^= mat[i][0]
	ans.append(1)
for i in range(n):
	if cur > 0:
		break
	for j in range(1, m):
		if cur ^ mat[i][0] ^ mat[i][j] > 0:
			ans[i] = j + 1
			cur ^= mat[i][0] ^ mat[i][j]
			break
if cur == 0:
	print('NIE')
else:
	print('TAK')
	print(*ans)


(n, m) = [int(el) for el in input().split()]
matrix = list()
for i in range(n):
	matrix.append([int(el) for el in input().split()])
base = matrix[0][0]
for i in range(1, len(matrix)):
	base = base ^ matrix[i][0]
if base != 0:
	print('TAK')
	print(' '.join([str(el) for el in [1] * n]))
else:
	rem_j = -1
	for i in range(n):
		cur_base = matrix[i][0]
		for j in range(m):
			if cur_base ^ matrix[i][j] != 0:
				rem_j = j
				break
		if rem_j != -1:
			output_arr = [str(el) for el in [1] * n]
			output_arr[i] = str(rem_j + 1)
			print('TAK')
			print(' '.join(output_arr))
			break
	if rem_j == -1:
		print('NIE')


(n, m) = map(int, input().split())
arr = []
setArr = []
bad = 0
ans = []
stop = 0
for _ in range(n):
	next = list(map(int, input().split()))
	arr.append(next)

def selectPaht(a, row):
	global ans
	xor = 0
	temp = []
	for i in range(n):
		xor ^= arr[i][a[i]]
		temp.append(a[i] + 1)
	if xor == 0:
		for i in range(n):
			current = arr[i][0]
			for j in range(m):
				if current != arr[i][j]:
					temp[i] = j + 1
					ans = temp[:]
					return 1
	else:
		ans = temp[:]
search = [0] * n
selectPaht(search, -1)
if len(ans) > 0:
	print('TAK')
	print(*ans)
else:
	print('NIE')


def is_odds(row):
	return all((x % 2 == 1 for x in row))

def is_evens(row):
	return all((x % 2 == 0 for x in row))

def odd(row):
	for (i, x) in enumerate(row):
		if x % 2 == 1:
			return i + 1

def even(row):
	for (i, x) in enumerate(row):
		if x % 2 == 0:
			return i + 1

def solve(rows):
	odds = sum(map(is_odds, rows))
	evens = sum(map(is_evens, rows))
	if odds % 2 == 0 and odds + evens == len(rows):
		return
	print('TAK')
	flag = odds % 2 == 1
	result = []
	for row in rows:
		if is_odds(row) or is_evens(row):
			result.append(1)
		elif not flag:
			result.append(odd(row))
			flag = True
		else:
			result.append(even(row))
	print(' '.join(map(str, result)))
	exit()

def update(rows):
	for (i, row) in enumerate(rows):
		rows[i] = [x // 2 for x in row]

def main():
	(n, m) = map(int, input().split())
	rows = [list(map(int, input().split())) for _ in range(n)]
	for _ in range(11):
		solve(rows)
		update(rows)
	print('NIE')
main()


from functools import *
from operator import *
(n, m) = (int(x) for x in input().split())
a = [list((int(x) for x in input().split())) for i in range(n)]
r = list((0 for i in a))
x = reduce(xor, [a[i][r[i]] for i in range(n)], 0)
for i in range(n):
	for j in range(m):
		x = x ^ a[i][r[i]] ^ a[i][j]
		r[i] = j
		if x > 0:
			print('TAK')
			print(*(x + 1 for x in r))
			exit(0)
print('NIE')


import random

def xor_v(a):
	res = 0
	for i in a:
		res ^= i
	return res
(a, b) = list(map(int, input().split()))
m = []
for i in range(a):
	m.append(list(map(int, input().split())))
i = 0
res = 0
while i < 800 and res == 0:
	i += 1
	v = []
	x = []
	for j in range(a):
		idx = random.randint(0, b - 1)
		v.append(m[j][idx])
		x.append(idx + 1)
	res = xor_v(v)
	if res > 0:
		print('TAK')
		print(' '.join(list(map(str, x))))
		exit(0)
print('NIE')


(n, m) = map(int, input().split())
sr = n
bl = []
for i in range(n):
	a = list(map(int, input().split()))
	bl.append(a)
	if sr == n and len(set(a)) > 1:
		sr = i
		s = set(a)
if sr != n:
	print('TAK')
	ans = []
	x = 0
	for i in range(n):
		if i != sr:
			ans.append(1)
			x ^= bl[i][0]
	for i in s:
		if i == x:
			continue
		ind = bl[sr].index(i)
		ans = ans[:sr] + [ind + 1] + ans[sr:]
		break
	print(*ans)
else:
	x = 0
	for i in range(n):
		x ^= bl[i][0]
	if x:
		print('TAK')
		ans = [1] * n
		print(*ans)
	else:
		print('NIE')


(H, W) = map(int, input().split())
A = []
As = []
for h in range(H):
	A.append(list(map(int, input().split())))
	As.append(set(A[h]))

def dfs(h, xor1, hist):
	if h == H:
		if xor1 > 0:
			return hist
		else:
			return None
	for a in As[h]:
		ret = dfs(h + 1, xor1 ^ a, hist + [a])
		if ret is not None:
			return ret
	return None
hist = dfs(0, 0, [])
if hist is not None:
	print('TAK')
	print(*[A[h].index(hist[h]) + 1 for h in range(H)])
else:
	print('NIE')


(N, M) = map(int, input().split())
Matrix = []
for i in range(N):
	temp = [int(x) for x in input().split()]
	Matrix.append(temp)
index = -1
for i in range(N):
	if len(set(Matrix[i])) > 1:
		index = i
		break
if index == -1:
	Xor = 0
	for i in range(N):
		Xor ^= Matrix[i][0]
	if Xor:
		print('TAK')
		Ans = [1] * N
		print(*Ans)
	else:
		print('NIE')
else:
	Xor = 0
	for i in range(N):
		if i != index:
			Xor ^= Matrix[i][0]
	Value = list(set(Matrix[index]))
	Hit = -1
	for i in Value:
		if Xor ^ i:
			Hit = i
			break
	for i in range(M):
		if Matrix[index][i] == Hit:
			ii = i + 1
			break
	Ans = [1] * N
	Ans[index] = ii
	print('TAK')
	print(*Ans)


(n, m) = map(int, input().split())
arr = [None] * n
cx = 0
for i in range(n):
	arr[i] = [int(o) for o in input().split()]
	cx ^= arr[i][0]
ans = [1] * n
if cx != 0:
	print('TAK')
	print(*ans)
else:
	flag = 0
	for i in range(n):
		for j in range(1, m):
			if arr[i][j] != arr[i][0]:
				ans[i] = j + 1
				flag = 1
				break
		if flag == 1:
			break
	if flag == 0:
		print('NIE')
	else:
		print('TAK')
		print(*ans)


(n, m) = map(int, input().split())
bitbool = [[[-1 for k in range(2)] for j in range(10)] for i in range(n)]
for i in range(n):
	row = list(map(int, input().split()))
	for j in range(m):
		num = row[j]
		bits = [False for k in range(10)]
		for exp in range(9, -1, -1):
			k = pow(2, exp)
			if num >= k:
				num -= k
				bits[10 - exp - 1] = 1
			else:
				bits[10 - exp - 1] = 0
		for k in range(10):
			if bits[k] == 1:
				bitbool[i][k][1] = j
			else:
				bitbool[i][k][0] = j
found = False
for i in range(10):
	ans = ''
	numbits = 0
	atleast = 0
	for j in range(n):
		if bitbool[j][i][1] != -1 and bitbool[j][i][0] == -1:
			numbits += 1
		if bitbool[j][i][1] != -1 and bitbool[j][i][0] != -1:
			atleast += 1
	if numbits % 2 == 1:
		for j in range(n):
			if bitbool[j][i][1] != -1 and bitbool[j][i][0] == -1:
				ans += str(bitbool[j][i][1] + 1) + ' '
			else:
				ans += str(bitbool[j][i][0] + 1) + ' '
		found = True
		break
	elif atleast > 0:
		for j in range(n):
			if bitbool[j][i][1] != -1 and bitbool[j][i][0] == -1:
				ans += str(bitbool[j][i][1] + 1) + ' '
			elif atleast > 0 and bitbool[j][i][1] != -1 and (bitbool[j][i][0] != -1):
				atleast = 0
				ans += str(bitbool[j][i][1] + 1) + ' '
			else:
				ans += str(bitbool[j][i][0] + 1) + ' '
		found = True
		break
if found:
	print('TAK')
	print(ans)
else:
	print('NIE')


def groupxor(l):
	result = 0
	for item in l:
		result = result ^ item
	return result
(r, c) = [int(x) for x in input().split()]
rows = []
for _ in range(r):
	rows.append([int(x) for x in input().split()])
starts = [rows[j][0] for j in range(r)]
result = [1] * r
if groupxor(starts) == 0:
	notfixed = True
	for j in range(r):
		for k in range(1, c):
			if notfixed:
				if rows[j][0] != rows[j][k]:
					notfixed = False
					result[j] = k + 1
	if notfixed == True:
		print('NIE')
	else:
		print('TAK')
		print(' '.join([str(x) for x in result]))
else:
	print('TAK')
	print(' '.join([str(x) for x in result]))


def main():
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = [[0 for i in range(m)] for j in range(n)]
	for i in range(n):
		a[i] = [int(j) for j in input().split()]
	xor = 0
	for i in range(n):
		xor ^= a[i][0]
	if xor > 0:
		print('TAK')
		for i in range(n):
			print('1', end=' ')
		print()
	else:
		for i in range(n):
			for j in range(1, m):
				if xor ^ a[i][j] ^ a[i][0] > 0:
					print('TAK')
					for k in range(i):
						print('1', end=' ')
					print(j + 1, end=' ')
					for k in range(i + 1, n):
						print('1', end=' ')
					print()
					return
		print('NIE')
main()


from math import *
(n, m) = map(int, input().split())
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
xor = 0
for i in range(n):
	xor = xor ^ l[i][0]
if xor != 0:
	print('TAK')
	print('1 ' * n)
else:
	ind = -1
	flag = 0
	for i in range(n):
		for j in range(1, m):
			if l[i][j] != l[i][0]:
				ind = (i, j + 1)
				flag = 1
				break
		if flag == 1:
			break
	if flag == 0:
		print('NIE')
	else:
		print('TAK')
		for i in range(n):
			if i == ind[0]:
				print(ind[1], end=' ')
			else:
				print(1, end=' ')
		print()


import sys
import copy
sys.setrecursionlimit(1000000)
(n, m) = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(n)]
for b in range(10):
	one = [[] for i in range(n)]
	zero = [[] for i in range(n)]
	for i in range(n):
		for j in range(m):
			if c[i][j] & 1 << b:
				one[i].append(j)
			else:
				zero[i].append(j)
	ans = [-1] * n
	cnt = 0
	for i in range(n):
		if len(one[i]) == m:
			ans[i] = one[i][0]
			cnt += 1
	for i in range(n):
		if len(zero[i]) == m:
			ans[i] = zero[i][0]
	for i in range(n):
		if len(one[i]) != m and len(zero[i]) != m:
			if cnt % 2 == 0:
				ans[i] = one[i][0]
				cnt += 1
			else:
				ans[i] = zero[i][0]
	if cnt % 2 == 1:
		print('TAK')
		print(' '.join(map(lambda x: str(x + 1), ans)))
		exit()
print('NIE')


import sys
import copy
sys.setrecursionlimit(1000000)
(n, m) = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(n)]
hasMulti = False
X = 0
ans = [0] * n
for i in range(n):
	st = set(c[i])
	if len(st) > 1:
		hasMulti = True
	X ^= c[i][0]
if not hasMulti:
	if X == 0:
		print('NIE')
	else:
		print('TAK')
		print(' '.join(map(lambda x: str(x + 1), ans)))
	exit()
for i in range(n):
	if X != 0:
		continue
	st = set(c[i])
	if len(st) > 1:
		now = c[i][0]
		for j in range(m):
			if c[i][j] != now:
				ans[i] = j
				X ^= c[i][0]
				X ^= c[i][j]
				break
print('TAK')
print(' '.join(map(lambda x: str(x + 1), ans)))


from collections import defaultdict as df
from sys import stdin
from bisect import bisect_left as bl, bisect_right as br, insort
import heapq
from collections import deque
import math
from collections import defaultdict as df
from sys import stdin
from bisect import bisect_left as bl, bisect_right as br, insort
import heapq
from collections import deque
import math
(n, m) = list(map(int, input().split()))
a = [[0] * m for i in range(n)]
v = set()
ans = []
for i in range(n):
	b = list(map(int, input().rstrip().split()))
	for j in range(m):
		a[i][j] = b[j]
	v = v | set(b)
xori = 0
for i in range(n):
	xori = xori ^ a[i][0]
if xori != 0:
	print('TAK')
	for i in range(n):
		print('1', end=' ')
else:
	gg = 0
	for i in range(n):
		for j in range(1, m):
			if a[i][0] != a[i][j]:
				gg = 1
				ansi = i
				index = j
				break
		if gg == 1:
			break
	if gg == 1:
		print('TAK')
		for i in range(n):
			if i == ansi:
				print(index + 1, end=' ')
			else:
				print(1, end=' ')
	else:
		print('NIE')


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
for b in range(10):
	RB = [0] * n
	for j in range(n):
		SCORE = []
		for k in range(m):
			if A[j][k] & 1 << b == 0:
				SCORE.append(0)
			else:
				SCORE.append(1)
		SCORE = sorted(set(SCORE))
		if len(SCORE) == 2:
			print('TAK')
			ANS = [1] * n
			XOR = 0
			for k in range(n):
				if j == k:
					continue
				XOR ^= A[k][0] & 1 << b
			if XOR == 0:
				for k in range(m):
					if A[j][k] & 1 << b != 0:
						ANS[j] = k + 1
						print(*ANS)
						sys.exit()
			else:
				for k in range(m):
					if A[j][k] & 1 << b == 0:
						ANS[j] = k + 1
						print(*ANS)
						sys.exit()
		elif len(SCORE) == 1:
			RB[j] = SCORE[0]
	XOR = 0
	for i in range(n):
		XOR ^= RB[i]
	if XOR == 0:
		continue
	else:
		print('TAK')
		print(*[1] * n)
		sys.exit()
else:
	print('NIE')


(n, m) = map(int, input().split())
mat = [[int(x) for x in input().split()] for i in range(n)]
x = 0
for m in mat:
	x ^= m[0]
if x > 0:
	print('TAK')
	print('1 ' * n)
else:
	i = -1
	f = 0
	for m in mat:
		if f:
			break
		i += 1
		for k in range(len(m)):
			if m[k] != m[0]:
				f = k
				break
	if f:
		print('TAK')
		ans = [1] * n
		ans[i] = f + 1
		print(*ans)
	else:
		print('NIE')


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0
(n, m) = mp()
a = []
ans = []
dual = []
x = 0
for i in range(n):
	r = lmp()
	a.append(r)
	ans.append(1)
	x ^= r[0]
	if len(set(r)) > 1:
		dual.append(i)
if x != 0:
	print('TAK')
	print(*ans)
elif len(dual) > 0:
	xx = a[dual[0]][0]
	for j in range(m):
		if xx != a[dual[0]][j]:
			ans[dual[0]] = j + 1
			break
	print('TAK')
	print(*ans)
else:
	print('NIE')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	(n, m) = RL()
	arr = []
	for _ in range(n):
		arr.append(RLL())
	res = 0
	for i in range(n):
		res ^= arr[i][0]
	ret = [1] * n
	if res != 0:
		print('TAK')
		print(*ret)
	else:
		tag = False
		for i in range(n):
			for j in range(1, m):
				if arr[i][j] != arr[i][0]:
					ret[i] = j + 1
					tag = True
					break
			if tag:
				print('TAK')
				print(*ret)
				break
		else:
			print('NIE')
main()


(n, m) = list(map(int, input().split()))
a = []
b = []
x = 0
for i in range(n):
	a.append(list(map(int, input().split())))
	x = x ^ a[i][0]
	b.append(len(set(a[i])))
if x != 0:
	c = [1] * n
	print('TAK')
	print(*c)
else:
	d = []
	e = 0
	for i in range(len(b)):
		if b[i] > 1:
			e = 1
			for j in range(m):
				if a[i][j] != a[i][0]:
					c = [i, j + 1]
					break
			break
	if e == 0:
		print('NIE')
	else:
		d = []
		for i in range(n):
			if i == c[0]:
				d.append(c[1])
			else:
				d.append(1)
		print('TAK')
		print(*d)


import operator
from functools import reduce
(n, m) = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(n)]
yes = any((len(set(s)) > 1 for s in mat))
xor = reduce(operator.xor, [d[0] for d in mat])
if xor > 0:
	yes = True
index = ['1'] * n
if yes and xor == 0:
	for (i, row) in enumerate(mat):
		if len(set(row)) > 1:
			for (j, n) in enumerate(row):
				if n != row[0]:
					index[i] = str(j + 1)
					break
			break
print('TAK' if yes else 'NIE')
if yes:
	print(' '.join(index))


def main():
	(n, m) = map(int, input().split())
	a = [[0] * m for i in range(n + 5)]
	choose = [0] * 1000
	choice = [[0, 0] for i in range(n)]
	choiceind = []
	nochoice = 0
	for i in range(0, n):
		a[i] = list(map(int, input().split()))
		u = sorted(a[i])
		if u[m - 1] == u[0]:
			choose[i] = 0
			nochoice += 1
		else:
			for j in range(1, m):
				if a[i][j] != a[i][j - 1]:
					choice[i] = [j - 1, j]
					choiceind.append(i)
	if nochoice == n:
		val = 0
		for i in range(n):
			val = val ^ a[i][0]
		if val == 0:
			print('NIE')
			quit()
		else:
			print('TAK')
			for x in range(n):
				print(1, end=' ')
	else:
		print('TAK')
		val = 0
		for i in range(n):
			if i in choiceind:
				choose[i] = choice[i][0]
		for i in range(n):
			val = val ^ a[i][choose[i]]
		if val > 0:
			for x in range(n):
				print(choose[x] + 1, end=' ')
		else:
			choose[choiceind[0]] = choice[choiceind[0]][1]
			for x in range(n):
				print(choose[x] + 1, end=' ')
main()


R = lambda : map(int, input().split())
(n, m) = R()
t = None
cur = None
a = None
for i in range(n):
	a = tuple(R())
	s = list(set(a))
	if t is None and len(s) > 1:
		t = [(s[0], a.index(s[0])), a.index(s[1]), i]
	else:
		cur = a[0] if cur is None else cur ^ a[0]
if n == 1:
	ls = list(filter(lambda x: x[1], enumerate(a)))
	if ls:
		print('TAK')
		print(ls[0][0] + 1)
	else:
		print('NIE')
elif t:
	print('TAK')
	(p1, p2, row) = t
	col = p1[1] if p1[0] ^ cur else p2
	ls = [1] * row + [col + 1] + [1] * (n - row - 1)
	print(*ls, sep=' ')
elif cur:
	print('TAK')
	print(' '.join(['1'] * n))
else:
	print('NIE')


(n, m) = [int(t) for t in input().split()]

def xor(arr):
	t = 0
	for a in arr:
		t = t ^ a
	return t
a = []
win = False
j = 0
for i in range(n):
	tmp = [int(t) for t in input().split()]
	if len(set(tmp)) > 1:
		win = True
		j = i
	a.append(tmp)
if not win:
	if xor([t[0] for t in a]) == 0:
		print('NIE')
	else:
		print('TAK')
		print(' '.join(['1'] * n))
else:
	print('TAK')
	if xor([t[0] for t in a]) != 0:
		print(' '.join(['1'] * n))
	else:
		ans = ['1'] * n
		k = 1
		while a[j][k] == a[j][0]:
			k += 1
		ans[j] = str(k + 1)
		print(' '.join(ans))


answer = False
path = list()

def recur(num, list1, height, n):
	global answer
	global path
	global lists
	if answer:
		return
	if height == n:
		if num != 0:
			path = list1
			answer = True
		return
	s = list(lists[height])
	for x in s:
		recur(num ^ x, list1 + [x], height + 1, n)
(n, m) = map(int, input().split())
lists = [0] * n
lists2 = [0] * n
for i in range(0, n):
	b = list(map(int, input().split()))
	g = set(b)
	lists[i] = g
	lists2[i] = b
answer = False
recur(0, list(), 0, n)
print('NIE' if not answer else 'TAK')
x = ''
if answer:
	for i in range(0, len(path)):
		x += str(lists2[i].index(path[i]) + 1) + ' '
print(x.strip(), end='')


import math
import time
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import PriorityQueue
import sys
(n, m) = map(int, stdin.readline().split())
grid = []
for _ in range(n):
	grid.append(list(map(int, stdin.readline().split())))
ans = 0
ansL = [1] * n
for i in range(n):
	ans ^= grid[i][0]
if ans != 0:
	print('TAK')
	print(*ansL)
else:
	found = False
	for row in range(n):
		for col in range(1, m):
			if grid[row][col] != grid[row][0]:
				found = True
				ansL[row] = col + 1
				break
		if found:
			break
	if found:
		print('TAK')
		print(*ansL)
	else:
		print('NIE')


(n, m) = map(int, input().split())
matrix = []
for i in range(n):
	line = input().split()
	line = [int(x) for x in line]
	matrix.append(line)
total = 0
res = []
for line in matrix:
	total ^= line[0]
	res.append(1)
if total == 0:
	i = 0
	achei = False
	while i < n and achei == False:
		for j in range(1, m):
			if matrix[i][j] != matrix[i][0]:
				res[i] = j + 1
				achei = True
				break
		i += 1
else:
	achei = True
if achei == False:
	print('NIE')
else:
	print('TAK')
	for r in res:
		print(r, end=' ')
	print()


(n, m) = map(int, input().split())
a = [[int(s) for s in input().split()] for i in range(n)]
ans = [1] * n
x = a[0][0]
for i in range(1, n):
	x ^= a[i][0]
if x:
	print('TAK')
	print(*ans)
else:
	flag = False
	for i in range(n):
		if len(set(a[i])) > 1:
			flag = True
			for j in range(m):
				if a[i][j] != a[i][0]:
					ans[i] = j + 1
					break
			break
	if not flag:
		print('NIE')
	else:
		print('TAK')
		print(*ans)


(n, m) = map(int, input().split())
mat = []
for i in range(n):
	row = list(map(int, input().split()))
	mat.append(row)
idx = [0 for i in range(n)]
ans = 0
tot_cnt = 0
for i in range(n):
	ans ^= mat[i][idx[i]]
while ans == 0:
	j = n - 1
	while j >= 0:
		if idx[j] < m - 1:
			idx[j] += 1
			ans = ans ^ mat[j][idx[j] - 1] ^ mat[j][idx[j]]
			break
		j -= 1
		continue
	else:
		if j == -1:
			break
if ans:
	print('TAK')
	for i in idx[:-1]:
		print(i + 1, end=' ')
	print(idx[-1] + 1)
else:
	print('NIE')


from collections import Counter
(n, m) = map(int, input().split())
arr = []
for _ in range(n):
	arr.append(list(map(int, input().split())))
res = ['1'] * n
acc = 0
for i in range(n):
	acc ^= arr[i][0]
if acc > 0:
	print('TAK')
	print(' '.join(res))
else:
	i = 0
	while i < n and len(Counter(arr[i])) == 1:
		i += 1
	if i == n:
		print('NIE')
	else:
		j = 0
		while arr[i][j] == arr[i][0]:
			j += 1
		res[i] = str(j + 1)
		print('TAK')
		print(' '.join(res))


import sys
import os
from io import BytesIO, IOBase

def cel(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return defaultdict(int)

def ddl():
	return defaultdict(list)

def ddd():
	return defaultdict(defaultdict(int))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
for _ in range(1):
	(n, m) = mi()
	a = [li() for i in range(n)]
	res = [1 for i in range(n)]
	x = 0
	for i in range(n):
		x ^= a[i][0]
	if x > 0:
		print('TAK')
		print(*res)
	else:
		f = 0
		for i in range(n):
			for j in range(m):
				if a[i][j] != a[i][0]:
					res[i] = j + 1
					f = 1
					break
			if f == 1:
				break
		if f == 0:
			print('NIE')
		else:
			print('TAK')
			print(*res)


(n, m) = map(int, input().split())
mat = [[0 for i in range(m)] for j in range(n)]
for i in range(n):
	mat[i] = list(map(int, input().split()))
xor = 0
flag = 0
row = 0
for i in range(n):
	if mat[i].count(mat[i][0]) == m:
		xor = xor ^ mat[i][0]
	else:
		flag = 1
		row = i
		break
if flag == 0:
	if xor > 0:
		print('TAK')
		for i in range(n):
			print(1, end=' ')
	else:
		print('NIE')
else:
	(xor1, xor2) = (0, 0)
	(num1, num2) = (0, 0)
	for i in range(n):
		if i == row:
			temp = list(set(mat[i]))
			xor1 = xor1 ^ temp[0]
			num1 = temp[0]
			xor2 = xor2 ^ temp[1]
			num2 = temp[1]
		else:
			xor1 = xor1 ^ mat[i][0]
			xor2 = xor2 ^ mat[i][0]
	if xor1 > 0:
		print('TAK')
		for i in range(n):
			if i == row:
				print(mat[i].index(num1) + 1, end=' ')
			else:
				print(1, end=' ')
	elif xor2 > 0:
		print('TAK')
		for i in range(n):
			if i == row:
				print(mat[i].index(num2) + 1, end=' ')
			else:
				print(1, end=' ')
	else:
		print('NIE')


import sys
(n, m) = [int(x) for x in input().split()]
lines = []
for i in range(n):
	lines.append([bin(int(x))[2:].zfill(10) for x in input().split()])
odds = [-1 for _ in range(n)]
evens = [-1 for _ in range(n)]
for i in range(10):
	pos_even = True
	pos_odd = False
	for c in range(n):
		pos_even_temp = False
		pos_odd_temp = False
		for cur in range(m):
			if lines[c][cur][i] == '1':
				if pos_even:
					pos_odd_temp = True
					odds[c] = cur
				if pos_odd:
					pos_even_temp = True
					evens[c] = cur
			else:
				if pos_even:
					pos_even_temp = True
					evens[c] = cur
				if pos_odd:
					pos_odd_temp = True
					odds[c] = cur
		pos_even = pos_even_temp
		pos_odd = pos_odd_temp
	if pos_odd:
		print('TAK')
		res = []
		last_even = lines[n - 1][odds[n - 1]][i] != '1'
		res.append(odds[n - 1])
		for s in reversed(range(n - 1)):
			if last_even:
				res.append(odds[s])
				last_even = lines[s][odds[s]][i] != '1'
			else:
				res.append(evens[s])
				last_even = lines[s][evens[s]][i] == '1'
		res = reversed(res)
		for s in res:
			print(s + 1, end=' ')
		sys.exit()
print('NIE')


params = list(map(int, list(input().split())))
m = []
for _ in range(params[0]):
	m.append(list(map(int, list(input().split()))))
path = []
for row in m:
	s = set(row)
	path.append([row[0], len(s), 1])

def get_pos(path, r):
	for col in range(1, len(m[r])):
		if m[r][col] != m[r][0]:
			return (m[r][col], col + 1)
ans = 0
for step in path:
	ans = ans ^ step[0]
if ans == 0:
	for r in range(0, len(path)):
		if path[r][1] > 1:
			(path[r][0], path[r][2]) = get_pos(path, r)
			print('TAK')
			w = ''
			for step in path:
				w = w + str(step[2]) + ' '
			print(w[:-1])
			break
	else:
		print('NIE')
else:
	print('TAK')
	w = ''
	for step in path:
		w = w + str(step[2]) + ' '
	print(w[:-1])


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def solve(self):
		n = self.next_int()
		m = self.next_int()
		rr = None
		xor = 0
		for i in range(0, n):
			x = [self.next_int() for _ in range(0, m)]
			for j in range(1, m):
				if rr is not None:
					break
				if x[j] != x[0]:
					rr = (i, j)
			xor ^= x[0]
		if xor == 0:
			if rr is None:
				print('NIE')
			else:
				print('TAK')
				print(' '.join(['1' if i != rr[0] else str(rr[1] + 1) for i in range(0, n)]))
		else:
			print('TAK')
			print(' '.join(['1' for _ in range(0, n)]))
Main().solve()


(n, m) = map(int, input().split())
matrix = []
u = {k: {} for k in range(n)}
for i in range(n):
	a = list(map(int, input().split(' ')))
	for tro in range(m):
		u[i][a[tro]] = tro
	matrix.append(a)
dp = [[] for i in range(1024)]
avail = {}
for k in range(len(matrix[0])):
	dp[matrix[0][k]] = [matrix[0][k]]
	avail[matrix[0][k]] = 0
for pro in range(1, n):
	helpp = [[] for tro in range(1024)]
	oks = {}
	for tro in range(1024):
		for al in avail:
			if al ^ tro in u[pro] and dp[al]:
				helpp[tro] = dp[al] + [al ^ tro]
				oks[tro] = 0
				break
	dp = helpp
	avail = oks
flag = False
for k in avail:
	if k:
		print('TAK')
		for pro in range(n):
			print(u[pro][dp[k][pro]] + 1, end=' ')
		print()
		flag = True
		break
if not flag:
	print('NIE')


(n, m) = list(map(int, input().split()))
T = [[] for i in range(n)]
x = 0
d = [1] * n
for i in range(n):
	a = list(map(int, input().split()))
	T[i] = a
	x ^= a[0]
for i in range(n):
	for j in range(m):
		if x ^ T[i][0] ^ T[i][j] != 0:
			print('TAK')
			d[i] = j + 1
			print(*d)
			exit()
print('NIE')


import sys
(n, m) = list(map(int, input().split()))
A = []
for i in range(n):
	A.append(list(map(int, input().split())))
initial = [0] * n
xx = 0
for i in range(len(initial)):
	idx = initial[i]
	xx = xx ^ A[i][idx]
if xx > 0:
	print('TAK')
	print(' '.join(list(map(lambda x: str(x + 1), initial))))
	sys.exit(0)
else:
	for i in range(0, n):
		for j in range(1, m):
			if A[i][j] != A[i][0]:
				initial[i] = j
				print('TAK')
				print(' '.join(list(map(lambda x: str(x + 1), initial))))
				sys.exit(0)
print('NIE')


from functools import reduce
from operator import xor

def read_ints():
	return list(map(int, input().split()))

def solve(M):
	r = [0] * len(M)
	sum = reduce(xor, [row[0] for row in M])
	if sum > 0:
		return r
	for (i, row) in enumerate(M):
		j = next((j for (j, x) in enumerate(row) if x != row[0]), -1)
		if j >= 0:
			r[i] = j
			return r
	return []
(n, m) = read_ints()
M = [read_ints() for _ in range(n)]
ids = solve(M)
if not ids:
	print('NIE')
else:
	print('TAK')
	print(' '.join(map(str, [id + 1 for id in ids])))


(n, m) = [int(x) for x in input().split()]
arr = []
for i in range(n):
	arr.append([int(x) for x in input().split()])
val = 0
pos = [1] * n
for i in range(n):
	val ^= arr[i][0]
if val > 0:
	print('TAK')
	print(*pos)
else:
	flag = 0
	for i in range(n):
		cur = arr[i][0]
		newval = val ^ cur
		for j in range(1, len(arr[i])):
			newval ^= arr[i][j]
			if newval > 0:
				val = newval
				pos[i] = j + 1
				flag = 1
				break
			newval ^= arr[i][j]
		newval ^= cur
		if flag:
			break
	if flag:
		print('TAK')
		print(*pos)
	else:
		print('NIE')


(n, m) = list(map(int, input().split()))
x = []
d = []
for i in range(n):
	y = list(map(int, input().split()))
	x.append(y)
	d.append(set(y))
ans = [1] * n
s = x[0][0]
for i in range(1, n):
	s = s ^ x[i][0]
if s == 0:
	j = -1
	for i in range(n):
		if len(d[i]) != 1:
			j = i
			break
	if j == -1:
		print('NIE')
	else:
		print('TAK')
		z = 1
		for i in range(m):
			if x[j][i] != x[j][0]:
				z = i + 1
				ans[j] = z
				break
		print(*ans)
else:
	print('TAK')
	print(*ans)


R = lambda : map(int, input().split())
(n, m) = R()
a = [[*R()] for _ in [0] * n]
s = j = 0
for (i, r) in enumerate(a):
	while j < m and r[j] == r[0]:
		j += 1
	if j < m:
		break
	j = 0
for r in a:
	s ^= r[0]
t = s ^ a[i][0] ^ a[i][j]
r = [1] * n
if s == t == 0:
	print('NIE')
	exit()
if t:
	r[i] = j + 1
print('TAK', *r)


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def computeLPSArray(pat, M, lps):
	len = 0
	lps[0]
	i = 1
	while i < M:
		if pat[i] == pat[len]:
			len += 1
			lps[i] = len
			i += 1
		elif len != 0:
			len = lps[len - 1]
		else:
			lps[i] = 0
			i += 1
m = 10 ** 9 + 7
t = 1
while t:
	t -= 1
	(n, m) = map(int, fastinput().split())
	x = [list(map(int, fastinput().split())) for _ in range(n)]
	initial = x[0][0]
	ans = [1] * n
	for i in range(1, n):
		initial ^= x[i][0]
	for i in range(n):
		for j in range(m):
			if initial ^ x[i][0] ^ x[i][j]:
				ans[i] = j + 1
				print('TAK')
				print(*ans)
				exit()
	print('NIE')


import sys
import math
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
(n, m) = intInp()
other = []
xor = 0
ans = []
for i in range(n):
	row = intInp()
	row_set = list(set(row))
	if len(row_set) > 1:
		other = [i, row.index(row_set[1]) + 1]
	xor ^= row_set[0]
	ans.append(row.index(row_set[0]) + 1)
if xor > 0:
	print('TAK')
	print(' '.join(map(str, ans)))
elif len(other) == 0:
	print('NIE')
else:
	ans[other[0]] = other[1]
	print('TAK')
	print(' '.join(map(str, ans)))


(m, n) = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(m)]
x = 0
for i in range(m):
	x ^= data[i][0]
if x > 0:
	print('TAK')
	print(*[1] * m)
else:
	for (i, d) in enumerate(data):
		s = set(d)
		if len(set(d)) > 1:
			for x in s:
				if x != d[0]:
					k = d.index(x)
					break
			print('TAK')
			print(*[1] * i + [k + 1] + [1] * (m - i - 1))
			break
	else:
		print('NIE')


(n, m) = map(int, input().split())
a = []
f = 0
ind = -1
for i in range(n):
	a.append(list(map(int, input().split())))
	k = len(set(a[-1]))
	if k > 1:
		f = 1
		ind = i
if ind == -1:
	xor = 0
	for i in range(n):
		xor ^= a[i][0]
	if xor == 0:
		print('NIE')
	else:
		print('TAK')
		print('1 ' * n)
else:
	for i in range(m - 1):
		if a[ind][i] != a[ind][i + 1]:
			x = i
			y = i + 1
			break
	print('TAK')
	xor = 0
	for i in range(n):
		if i != ind:
			xor ^= a[i][0]
		else:
			xor ^= a[i][x]
	if xor == 0:
		for i in range(n):
			if i != ind:
				xor ^= a[i][0]
			else:
				xor ^= a[i][y]
		print('1 ' * ind + (str(y + 1) + ' ') + '1 ' * (n - ind - 1))
	else:
		print('1 ' * ind + (str(x + 1) + ' ') + '1 ' * (n - ind - 1))


import sys

def input():
	return sys.stdin.readline()[:-1]

def getInt():
	return int(input())

def getIntIter():
	return map(int, input().split())

def getIntList():
	return list(getIntIter())

def flush():
	sys.stdout.flush()
(n, m) = getIntIter()
key = -1
curr = 0
for x in range(n):
	row = getIntList()
	if min(row) == max(row) or key != -1:
		curr ^= row[0]
	elif key == -1:
		key = [x, row.index(min(row)) + 1, row.index(max(row)) + 1, min(row), max(row)]
if key == -1 and curr == 0:
	print('NIE')
else:
	sol = ['1'] * n
	if key != -1:
		if curr == key[3]:
			sol[key[0]] = str(key[2])
		else:
			sol[key[0]] = str(key[1])
	print('TAK')
	print(' '.join(sol))


import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
from math import gcd

def dtb(n):
	return bin(n).replace('0b', '')
(n, m) = map(int, input().split())
a = []
for _ in range(n):
	a.append(list(map(int, input().split())))
b = [set(a[i]) for i in range(n)]
ck = [0] * n
t = 0
for i in range(n):
	ck[i] = b[i].pop()
	t = t ^ ck[i]
if t == 0:
	for i in range(n):
		if b[i]:
			t = t ^ ck[i]
			ck[i] = b[i].pop()
			t = t ^ ck[i]
			break
if t:
	print('TAK')
	for i in range(n):
		print(a[i].index(ck[i]) + 1, end=' ')
	print()
else:
	print('NIE')


(n, m) = map(int, input().split())
a = [[int(i) for i in input().split()] for _ in range(n)]
t = a[0][0]
for i in range(1, n):
	t ^= a[i][0]
if t != 0:
	print('TAK')
	print(' '.join(('1' for i in range(n))))
else:
	for i in range(n):
		for j in range(1, m):
			if a[i][j] != a[i][0]:
				print('TAK')
				for t in range(i):
					print(1, end=' ')
				print(j + 1, end=' ')
				for t in range(i + 1, n):
					print(1, end=' ')
				exit(0)
	print('NIE')


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
x = 0
for v in a:
	x ^= v[0]
if x:
	print('TAK')
	print(*[1] * n)
else:

	def go():
		for i in range(n):
			for j in range(m):
				if a[i][j] != a[i][0]:
					v = [1] * n
					v[i] = j + 1
					print('TAK')
					print(*v)
					return
		print('NIE')
	go()


(n, m) = map(int, input().split())
num = []
key = []
non_one = []
ans_idx = [0] * n
for i in range(n):
	l = map(int, input().split())
	dt = dict()
	for (j, it) in enumerate(l):
		dt[it] = j
	num.append(dt)
	ky = sorted(dt.keys())
	if len(ky) != 1:
		non_one.append(i)
	key.append(sorted(dt.keys()))
ans = 0
for i in range(n):
	ans ^= key[i][0]
if ans != 0:
	print('TAK')
	for i in range(n):
		print(num[i][key[i][0]] + 1, end=' ')
elif len(non_one) == 0:
	print('NIE')
else:
	print('TAK')
	ans_idx[non_one[0]] = 1
	for i in range(n):
		print(num[i][key[i][ans_idx[i]]] + 1, end=' ')


import sys
(n, m) = list(map(int, input().split()))
table = []
xor_test = 0
for _ in range(n):
	temp = list(map(int, input().split()))
	table.append(temp)
	xor_test ^= temp[0]
if xor_test != 0:
	print('TAK')
	for _ in range(len(table)):
		print(1, end=' ')
	sys.exit()
result_r = -1
result_c = -1
for i in range(len(table)):
	test = table[i][0]
	for j in range(1, len(table[i])):
		if table[i][j] != test:
			result_r = i
			result_c = j
			break
	if result_c != -1:
		break
if result_c == -1:
	print('NIE')
	sys.exit()
print('TAK')
for _ in range(result_r):
	print(1, end=' ')
print(result_c + 1, end=' ')
for _ in range(result_r + 1, len(table)):
	print(1, end=' ')


import functools

def solve():
	(row, col) = [int(i) for i in str.split(input(), ' ')]
	m = []
	for i in range(row):
		m.append(list(map(int, str.split(input(), ' '))))
	total = functools.reduce(lambda x, y: x ^ y, list(map(lambda x: x[0], m)))
	if total == 0:
		for i in range(row):
			for j in range(1, col):
				if m[i][j] != m[i][0]:
					print('TAK\n' + ' '.join(['1'] * i + [str(j + 1)] + ['1'] * (row - i - 1)))
					return
		print('NIE')
	else:
		print('TAK\n' + ' '.join(['1'] * row))
solve()


(n, m) = map(int, input().split())
ans = []
flag = 0
for i in range(n):
	z = list(map(int, input().split()))
	ans.append(z)
	if i == 0:
		fin = z[0]
	else:
		fin = fin ^ z[0]
flag = 0
if fin:
	flag = 1
	print('TAK')
	for i in range(n):
		print(1, end=' ')
	exit()
else:
	for i in range(len(ans)):
		temp = ans[i]
		for j in range(1, len(temp)):
			if ans[i][j] != ans[i][0]:
				flag = 1
				print('TAK')
				for t in range(n):
					if t == i:
						print(j + 1, end=' ')
					else:
						print(1, end=' ')
				exit()
print('NIE')


(n, m) = map(int, input().split())
A = []
T = False
ind = -1
for i in range(n):
	B = list(map(int, input().split()))
	if len(set(B)) > 1:
		T = True
		ind = i
	A.append(B)
if T:
	print('TAK')
	ans = 0
	for i in range(n):
		if i != ind:
			ans ^= A[i][0]
	for j in range(m):
		if ans ^ A[ind][j] > 0:
			for i in range(n):
				if i == ind:
					print(j + 1, end=' ')
				else:
					print(1, end=' ')
			break
else:
	ans = 0
	for i in range(n):
		ans ^= A[i][0]
	if ans != 0:
		print('TAK')
		for i in range(n):
			print(1, end=' ')
	else:
		print('NIE')


def check(M, n, m):
	A = []
	xxor = 0
	for i in range(n):
		xxor ^= M[i][0]
		A.append(1)
	if xxor != 0:
		print('TAK')
		print(*A)
		return
	for i in range(n):
		for j in range(1, m):
			if M[i][j] != M[i][0]:
				A[i] = j + 1
				print('TAK')
				print(*A)
				return
	print('NIE')
(n, m) = map(int, input().split())
M = []
for i in range(n):
	a = list(map(int, input().split()))
	M.append(a)
check(M, n, m)


(m, n) = map(int, input().split())

def get_unique(array):
	unique_array = []
	for value in array:
		if value not in unique_array:
			unique_array.append(value)
	return unique_array
matrix = []
ori_matrix = []
matrix_idx_controller = [0] * m
multiple_n_idx = set()
ans = 0
for i in range(m):
	j = list(map(int, input().split()))
	j_copy = list(j).copy()
	ori_matrix.append(j_copy)
	j = get_unique(j)
	matrix.append(j)
	if len(j) > 1:
		multiple_n_idx.add(i)
	ans ^= j[0]
try:
	while ans == 0:
		idx = multiple_n_idx.pop()
		matrix_idx_controller[idx] += 1
		controller = matrix_idx_controller[idx]
		ans ^= matrix[idx][controller - 1]
		ans ^= matrix[idx][controller]
	print('TAK')
	answer = []
	for (idx, ans) in enumerate(matrix_idx_controller):
		answer.append(str(ori_matrix[idx].index(matrix[idx][matrix_idx_controller[idx]]) + 1))
	answer = ' '.join(answer)
	print(answer)
except KeyError:
	print('NIE')


(n, m) = map(int, input().split())
b = []
a = []
xor = 0
for i in range(n):
	l = list(map(int, input().split()))
	xor ^= l[0]
	a.append(len(set(l)))
	b.append(l)
if xor != 0:
	print('TAK')
	ans = [1] * n
	print(*ans)
else:
	ans = [1] * n
	flag = 0
	for i in range(len(a)):
		if a[i] > 1:
			flag = 1
			for j in range(m):
				if b[i][j] != b[i][0]:
					ans[i] = j + 1
					break
			break
	if flag == 0:
		print('NIE')
	else:
		print('TAK')
		print(*ans)


(n, m) = map(int, input().split())
tab = []
for i in range(n):
	a = map(int, input().split())
	tab.append(list(a))
k = -1
for i in range(n):
	s = set()
	for j in range(m):
		s.add(tab[i][j])
	if len(s) > 1:
		k = i
		break
res = [1] * n
t = 0
for i in range(n):
	if i != k:
		t = t ^ tab[i][0]
if k == -1:
	if t == 0:
		print('NIE')
	else:
		print('TAK')
		print(*res)
else:
	for i in range(m):
		if t ^ tab[k][i] != 0:
			res[k] = i + 1
			print('TAK')
			print(*res)
			break
	else:
		print('NIE')


(sizeI, sizeJ) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(sizeI)]
ret = [0] * sizeI
xor = 0
for i in range(sizeI):
	xor ^= a[i][0]
for i in range(sizeI):
	if xor > 0:
		break
	for j in range(sizeJ):
		if xor ^ a[i][0] ^ a[i][j] > 0:
			ret[i] = j
			xor ^= a[i][0] ^ a[i][j]
			break
if xor == 0:
	print('NIE')
else:
	print('TAK')
	print(*map(lambda x: x + 1, ret))


(n, m) = map(int, input().split())
l = []
for i in range(n):
	x = list(map(int, input().split()))
	l.append(x)
xor = 0
a = []
for i in range(n):
	xor ^= l[i][0]
	a.append(1)
if xor == 0:
	for i in range(n):
		x = l[i][0]
		flag = 0
		for j in range(m):
			if l[i][j] != x:
				a[i] = j + 1
				print('TAK')
				print(' '.join(map(str, a)))
				flag = 1
				break
		if flag == 1:
			break
	if flag == 0:
		print('NIE')
else:
	print('TAK')
	print(' '.join(map(str, a)))


(n, m) = map(int, input().split())
a = [0 for j in range(n)]
for i in range(n):
	a[i] = list(map(int, input().split()))
c = [1] * n
xor = 0
for i in range(n):
	xor = xor ^ a[i][c[i] - 1]
for i in range(n):
	flag = False
	for j in range(1, m + 1):
		cold = c[i]
		c[i] = j
		xor = xor ^ a[i][cold - 1]
		xor = xor ^ a[i][c[i] - 1]
		if xor != 0:
			print('TAK')
			print(*c)
			flag = True
			break
	if flag:
		break
else:
	print('NIE')


(n, m) = map(int, input().split())
a = [[*map(int, input().split())] for _ in range(n)]
for b in range(10):
	inds = []
	for r in range(n):
		i = [-1, -1]
		for c in range(m):
			i[a[r][c] >> b & 1] = c
		inds.append(i)
	tot = 0
	opt = -1
	for r in range(n):
		if -1 not in inds[r]:
			opt = r
		tot += inds[r][0] == -1
	tot &= 1
	if tot == 0 and opt == -1:
		continue
	print('TAK')
	ans = []
	for r in range(n):
		if opt == r and tot == 0:
			ans.append(inds[r][1] + 1)
		else:
			ans.append(inds[r][inds[r][0] == -1] + 1)
	print(*ans)
	break
else:
	print('NIE')


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
l = []
cur = 0
ans = []
for i in range(n):
	l.append(0)
	cur ^= a[i][0]
if cur > 0:
	print('TAK')
	for i in range(n):
		print(l[i] + 1, end=' ')
else:
	for i in range(n):
		t = -1
		for j in range(m):
			if a[i][j] != a[i][0]:
				t = j
		if t != -1:
			l[i] = t
			cur = 1
			break
	if cur > 0:
		print('TAK')
		for i in range(n):
			print(l[i] + 1, end=' ')
	else:
		print('NIE')


def xor(m, v):
	a = 0
	for (i, j) in enumerate(v):
		a = a ^ m[i][j]
	if a:
		return True
	return False

def main():
	(n, m) = [int(x) for x in input().split()]
	v = []
	for i in range(n):
		line = [int(x) for x in input().split()]
		v.append(line)
	ans = [0] * n
	for i in range(n):
		for j in range(m):
			if j < m - 1 and v[i][j] == v[i][j - 1]:
				continue
			ans[i] = j
			if xor(v, ans):
				print('TAK')
				ans = [x + 1 for x in ans]
				print(' '.join(map(str, ans)))
				return
	print('NIE')
main()


(n, m) = map(int, input().split())
list1 = []
for i in range(n):
	temp = list(map(int, input().split()))
	list1.append(temp)
temp = 0
ans = [1 for i in range(n)]
for i in range(n):
	temp = temp ^ list1[i][0]
if temp > 0:
	print('TAK')
	print(*ans)
else:
	f = 0
	for i in range(n):
		for j in range(1, m):
			if list1[i][j] != list1[i][0]:
				ans[i] = j + 1
				f = 1
				break
		if f == 1:
			break
	if f == 0:
		print('NIE')
	else:
		print('TAK')
		print(*ans)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	b = list(map(int, input().split()))
	a.append(b)
p = 0
c = []
for i in range(0, n - 1):
	p = a[i][0] ^ p
	c.append(1)
k = a[n - 1]
q = 0
for j in range(m):
	if k[j] != p:
		c.append(j + 1)
		q = 1
		break
if q == 0:
	c.append(1)
	for i in range(0, n - 1):
		l = a[i]
		for j in range(1, m):
			if l[j] != l[0]:
				q = 1
				c[i] = j + 1
				break
		if q == 1:
			break
if n == 1 and p != 0:
	print('YES')
elif q == 1:
	print('TAK')
	print(*c)
else:
	print('NIE')


import sys
(n, m) = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(n)]
x = 0
b = False
ans = 0
a = []
for i in range(n):
	for j in range(m):
		if s[i][j] != s[i][0]:
			b = True
			x = i
if b:
	for i in range(n):
		if x == i:
			continue
		ans ^= s[i][0]
	for i in range(m):
		if ans != s[x][i]:
			print('TAK')
			for j in range(n):
				a.append(i + 1 if x == j else 1)
			print(*a)
			sys.exit()
for i in range(n):
	ans ^= s[i][0]
	a.append(1)
if ans == 0:
	print('NIE')
else:
	print('TAK')
	print(*a)


(n, m) = map(int, input().split())
l = []
temp = 0
for i in range(n):
	k = list(map(int, input().split()))
	if i == 0:
		temp = k[0]
	else:
		temp = temp ^ k[0]
	l.append(k)
if temp > 0:
	print('TAK')
	for i in range(n):
		print(1, end=' ')
else:
	count = 0
	bo = -2
	for i in l:
		s = i[0]
		t = set(list(i))
		flag = 0
		for j in t:
			if j != s:
				flag = 1
				break
		if flag == 1:
			for k in range(len(i)):
				if j == i[k]:
					bo = k
					break
		if flag == 1:
			break
		count += 1
	if flag == 1:
		print('TAK')
		for i in range(n):
			if i == count:
				print(bo + 1, end=' ')
			else:
				print(1, end=' ')
	else:
		print('NIE')


x = []
(n, m) = list(map(int, input().strip().split()))

def find(i, p):
	if i == n:
		return (p, [])
	for j in x[i]:
		(v, path) = find(i + 1, p ^ j)
		if v:
			path.append(x[i][j])
			return (v, path)
	return (0, [])
for i in range(n):
	p = map(int, input().strip().split())
	p = {v: i for (i, v) in enumerate(p)}
	x.append(p)
(v, ans) = find(0, 0)
if v != 0:
	ans = ' '.join(map(lambda x: str(x + 1), reversed(ans)))
	print('TAK')
	print(ans)
else:
	print('NIE')


import sys
(n, m) = map(int, input().split())
M = [[int(el) for el in input().split()] for _ in range(n)]
res = 0
for i in range(n):
	res ^= M[i][0]
if res:
	print('TAK')
	print(*[1 for _ in range(n)])
else:
	res = [1] * n
	for i in range(n):
		for j in range(m):
			if M[i][j] != M[i][0]:
				res[i] = j + 1
				print('TAK')
				print(*res)
				sys.exit(0)
	print('NIE')


(n, m) = [int(x) for x in input().split()]
answer = []
xor = 0
total = []
for i in range(n):
	a = [int(x) for x in input().split()]
	answer.append(a)
for item in answer:
	xor ^= item[0]
	total.append(1)
if xor > 0:
	print('TAK')
	print(*total)
else:
	for i in range(n):
		for j in range(m):
			if answer[i][j] != answer[i][0]:
				total[i] = j + 1
				print('TAK')
				print(*total)
				exit()
	print('NIE')


(r, c) = list(map(int, input().split()))
arr = []
for i in range(r):
	lista = list(map(int, input().split()))
	arr.append(lista)
a = 0
ans = [1 for i in range(r)]
for i in range(r):
	a = a ^ arr[i][0]
flag = 0
if a > 0:
	print('TAK')
	print(*ans)
elif a == 0:
	for i in range(r):
		for j in range(1, c):
			if arr[i][0] != arr[i][j]:
				flag = 1
				ans[i] = j + 1
				break
		if flag == 1:
			break
	if flag == 0:
		print('NIE')
	else:
		print('TAK')
		print(*ans)


import sys
(n, m) = [int(x) for x in input().split()]
a = [[] for i in range(n)]
for i in range(n):
	a[i] = [int(x) for x in input().split()]
mask = 1
while mask <= 1024:
	(z, nz, both) = (0, 0, 0)
	cur = [[] for i in range(n)]
	for i in range(n):
		(j0, j1) = (m, m)
		for j in range(m):
			if a[i][j] & mask > 0:
				j1 = j
			else:
				j0 = j
		if j0 != m and j1 == m:
			z += 1
		elif j0 == m and j1 != m:
			nz += 1
		else:
			both += 1
		cur[i] = [j0, j1]
	if nz % 2 == 1:
		print('TAK')
		ans = [0] * n
		for i in range(n):
			if cur[i][0] == m and cur[i][1] != m:
				ans[i] = cur[i][1] + 1
			else:
				ans[i] = cur[i][0] + 1
		print(*ans, sep=' ')
		sys.exit()
	if both > 0:
		need = True
		print('TAK')
		ans = [0] * n
		for i in range(n):
			if cur[i][0] == m and cur[i][1] != m:
				ans[i] = cur[i][1] + 1
			elif cur[i][1] != m and need:
				ans[i] = cur[i][1] + 1
				need = False
			else:
				ans[i] = cur[i][0] + 1
		print(*ans, sep=' ')
		sys.exit()
	mask *= 2
print('NIE')


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
x = a[0][m - 1]
for i in range(1, n):
	x = x ^ a[i][m - 1]
res = [m] * n
if x == 0:
	c = False
	for i in range(n):
		for j in range(m - 1):
			if a[i][j] != a[i][-1]:
				res[i] = j + 1
				c = True
				print('TAK')
				print(' '.join(map(str, res)))
				break
		if c:
			break
	else:
		print('NIE')
else:
	print('TAK')
	print(' '.join(map(str, res)))


(n, m) = (int(x) for x in input().split())
matrix = [[int(x) for x in input().split()] for _ in range(n)]
my_xor = 0
ans = [1 for _ in range(n)]
for i in range(n):
	my_xor ^= matrix[i][0]
if my_xor > 0:
	print('TAK')
	print(*ans)
	quit()
for i in range(n):
	s = set(matrix[i])
	if len(s) > 1:
		my_xor ^= matrix[i][0]
	s.remove(matrix[i][0])
	for j in range(1, m):
		if matrix[i][j] in s:
			s.remove(matrix[i][j])
			my_xor ^= matrix[i][j]
			if my_xor > 0:
				ans[i] = j + 1
				print('TAK')
				print(*ans)
				quit()
			my_xor ^= matrix[i][j]
print('NIE')


import sys
input = sys.stdin.readline
(n, m) = list(map(int, input().split()))
a = [None] * n
d = [None] * n
for i in range(n):
	a[i] = input().split()
	d[i] = list(map(int, set(a[i])))
	a[i] = list(map(int, a[i]))

def func(x, c, b):
	if len(c) == 0:
		if x != 0:
			print('TAK')
			print(*[a[i].index(d[i][b[i]]) + 1 for i in range(len(b))])
			return True
		else:
			return False
	for (i, y) in enumerate(c[0]):
		if func(x ^ y, c[1:], b + [i]):
			return True
	return False
if not func(0, d, []):
	print('NIE')


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	(N, M) = getInts()
	grid = []
	flag = False
	for n in range(N):
		grid.append(getInts())
		if not flag and len(set(grid[n])) > 1:
			flag = True
			idx = n
	if not flag:
		curr = 0
		for n in range(N):
			curr ^= grid[n][0]
		if curr:
			print('TAK')
			ans = [1] * N
			print(*ans)
			return
		print('NIE')
		return
	curr = 0
	for n in range(N):
		if n != idx:
			curr ^= grid[n][0]
	for m in range(M):
		if curr ^ grid[idx][m] > 0:
			break
	ans = [1] * idx + [m + 1] + [1] * (N - idx - 1)
	print('TAK')
	print(*ans)
	return
solve()


def mp():
	return map(int, input().split())

def f():
	global j, n
	r = 0
	for i in range(n):
		r ^= a[i][j[i]]
	return r
(n, m) = mp()
a = [list(mp()) for i in range(n)]
j = [0] * n
if f() == 0:
	for i in range(n):
		ac = 0
		for q in range(m):
			if a[i][q] != a[i][0]:
				j[i] = q
				ac = 1
				break
		if ac:
			break
if f() == 0:
	print('NIE')
else:
	print('TAK')
	print(' '.join([str(i + 1) for i in j]))


def cin():
	return map(int, input().split())

def cino(test=False):
	if not test:
		return int(input())
	else:
		return input()

def cina():
	return list(map(int, input().split()))

def ssplit():
	return list(input().split())

def printlist(l):
	for i in l:
		print(i, end=' ')

def main():
	(n, m) = cin()
	l = []
	for _ in range(n):
		l1 = cina()
		l.append(l1)
	ans = 0
	for i in range(n):
		ans = ans ^ l[i][0]
	z = [1] * n
	if ans > 0:
		print('TAK')
		printlist(z)
	else:
		for i in range(n):
			for j in range(1, m):
				if l[i][0] != l[i][j]:
					z[i] = j + 1
					print('TAK')
					printlist(z)
					return
		print('NIE')
main()


import sys
(n, m) = [int(x) for x in input().split()]
a = []
for i in range(n):
	a += [[int(x) for x in input().split()]]
path = [0 for _ in range(n)]

def solve(i, curxor):
	if i == n:
		if curxor != 0:
			print('TAK')
			print(' '.join((str(i + 1) for i in path)))
			sys.exit(0)
		else:
			return False
	seen = set()
	for j in range(m):
		if a[i][j] not in seen:
			seen.add(a[i][j])
			path[i] = j
			solve(i + 1, curxor ^ a[i][j])
if not solve(0, 0):
	print('NIE')


import copy
(n, m) = map(int, input().strip().split())
matrix = [0] * n
no_pos = 1
for i in range(n):
	matrix[i] = list(map(int, input().strip().split()))
	sorted_mat = sorted(matrix[i])
	if any(matrix[i]) > 0:
		no_pos = 0
if no_pos == 1:
	print('NIE')
	exit(0)

def incr_sol(sol, n, m):
	new_sol = copy.deepcopy(sol)
	for i in range(n):
		if len(set(matrix[i])) > 1:
			cur = matrix[i][new_sol[i]]
			for (index, element) in enumerate(matrix[i]):
				if element == cur:
					continue
				else:
					new_sol[i] = index
					return new_sol
	return -1
while 1:
	sol = [0] * n
	result = 0
	for i in range(n):
		result ^= matrix[i][sol[i]]
	if result == 0:
		sol = incr_sol(sol, n, m)
		if sol == -1:
			print('NIE')
			exit(0)
	print('TAK')
	one_index = map(lambda x: x + 1, sol)
	print(' '.join(map(str, one_index)))
	exit(0)
	print('NIE')
	exit(0)


(n, m) = map(int, input().split())
matrix = []
for i in range(n):
	l = list(map(int, input().split()))
	matrix.append(l)
ans = 0
for i in range(n):
	ans ^= matrix[i][0]
to_print = [1] * n
for i in range(n):
	if len(set(matrix[i])) > 1:
		for j in range(m):
			if matrix[i][j] ^ matrix[i][0] ^ ans > 0:
				to_print[i] = j + 1
		print('TAK')
		print(*to_print)
		break
else:
	if ans > 0:
		print('TAK')
		print(*to_print)
	else:
		print('NIE')


import sys
from math import gcd
import bisect
import heapq
from collections import deque
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 998244353
flag = False
(n, m) = Ri()
arr = []
for i in range(n):
	temp = Ri()
	arr.append(temp)
ts = set()
ind = -1
for i in range(n):
	s = set()
	for j in range(m):
		s.add(arr[i][j])
	if len(s) > 1:
		ind = i
		ts = s
		flag = True
		break
xor = 0
val = -1
for i in range(n):
	if i == ind:
		val = arr[i][0]
	xor = xor ^ arr[i][0]
if xor == 0:
	if not flag:
		print('NIE')
	else:
		print('TAK')
		for i in range(n):
			if ind == i:
				for j in range(m):
					if arr[i][j] != arr[i][0]:
						print(j + 1, end=' ')
						break
			else:
				print(1, end=' ')
else:
	print('TAK')
	print(*[1] * n)


(n, m) = map(int, input().split())
l = []
xor = 0
for i in range(n):
	l1 = list(map(int, input().split()))
	l.append(l1)
	if i == 0:
		xor = l1[0]
	else:
		xor = xor ^ l1[0]
if xor != 0:
	print('TAK')
	print('1 ' * n)
else:
	l1 = [1] * n
	f = False
	for i in range(n):
		for j in range(m):
			if l[i][j] != l[i][0]:
				l1[i] = j + 1
				f = True
				break
		if f:
			break
	if f:
		print('TAK')
		print(*l1)
	else:
		print('NIE')


(N, M) = map(int, input().split())
X = [[int(a) for a in input().split()] for i in range(N)]
(i0, j0) = (-1, -1)
for i in range(N):
	for j in range(M - 1):
		if X[i][j] != X[i][j + 1]:
			(i0, j0) = (i, j + 1)
			break
	if i0 >= 0:
		break
s = 0
for i in range(N):
	s ^= X[i][0]
if s > 0:
	print('TAK')
	print(*[1] * N)
elif i0 >= 0:
	print('TAK')
	print(*[1] * i0 + [j0 + 1] + [1] * (N - i0 - 1))
else:
	print('NIE')


import collections
import heapq
import bisect
import math
import time

class Solution2:

	def solve(self, A1, A2):
		pass

def gcd(a, b):
	if not b:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return b * a // gcd(b, a)

class Solution:

	def solve(self, grid):
		if all((len(set(row)) == 1 for row in grid)):
			out = 0
			for i in range(len(grid)):
				out ^= grid[i][0]
			if out:
				print('TAK')
				return [1] * len(grid)
			print('NIE')
			return []
		out = []
		opt = []
		sofar = 0
		for i in range(len(grid)):
			curr = {}
			for j in range(len(grid[0])):
				curr[grid[i][j]] = j
			if len(curr) > 1:
				(opt1, opt2) = [(k, v + 1) for (k, v) in list(curr.items())[:2]]
				print('TAK')
				for r in range(i + 1, len(grid)):
					sofar ^= grid[r][0]
				if opt1[0] ^ sofar != 0:
					return out + [opt1[1]] + [1] * (len(grid) - i - 1)
				else:
					return out + [opt2[1]] + [1] * (len(grid) - i - 1)
			else:
				sofar ^= grid[i][0]
				out.append(1)
		print('NIE')
		return []
sol = Solution()
sol2 = Solution2()
for test_case in range(1):
	(N, K) = input().split()
	a = []
	for _ in range(int(N)):
		a.append([int(c) for c in input().split()])
	out = sol.solve(a)
	print(' '.join([str(o) for o in out]))


(n, m) = [int(i) for i in input().split()]
a = []
for i in range(n):
	a.append([int(j) for j in input().split()])
arr = []
xor = 0
for i in range(n):
	xor ^= a[i][0]
	arr.append(1)
if xor:
	print('TAK')
	print(*arr)
else:
	flag = 0
	for i in range(n):
		val = xor
		val ^= a[i][0]
		for j in range(1, m):
			if val ^ a[i][j] > 0:
				flag = 1
				arr[i] = j + 1
				break
		if flag:
			break
	if flag:
		print('TAK')
		print(*arr)
	else:
		print('NIE')


def main():
	(n, m) = list(map(int, input().split(' ')))
	num = []
	for i in range(n):
		num.append(list(map(int, input().split(' '))))
	ans = 0
	for i in range(n):
		ans ^= num[i][0]
	if ans != 0:
		print('TAK')
		for i in range(n):
			print(1, end=' ')
		print('\n')
		return
	else:
		for i in range(n):
			for j in range(m):
				if num[i][j] != num[i][0]:
					print('TAK')
					for k in range(n):
						if k != i:
							print(1, end=' ')
						else:
							print(j + 1, end=' ')
					print('\n')
					return
	print('NIE\n')
main()


def matrixNdxor(n, m):
	matrix = []
	firstXor = 0
	for i in range(n):
		row = []
		values = input()
		values = values.split()
		for j in range(m):
			row.append(int(values[j]))
		matrix.append(row)
		firstXor ^= int(values[0])
	return [matrix, firstXor]

def finder(n, m, matrix, firstXor):
	ans = ''
	for i in range(n):
		for j in range(1, m):
			if matrix[i][j] != matrix[i][0]:
				for a in range(n):
					if a == i:
						ans += str(j + 1) + ' '
					else:
						ans += '1 '
				return ans
	return False
values = input()
(n, m) = values.split()
n = int(n)
m = int(m)
(matrix, firstXor) = matrixNdxor(n, m)
if firstXor > 0:
	print('TAK')
	ans = ''
	for i in range(n):
		ans += '1 '
	print(ans)
else:
	res = finder(n, m, matrix, firstXor)
	if res != False:
		print('TAK')
		print(res)
	else:
		print('NIE')


import sys, os, io
import math, bisect, operator
(inf, mod) = (float('inf'), 10 ** 9 + 7)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int, input().split()))
(n, m) = Neo()
A = [Neo() for _ in range(n)]
import random
for i in range(2000):
	ind = []
	for j in range(n):
		t = random.randint(1, m)
		ind.append(t)
	t = 0
	for j in range(n):
		t ^= A[j][ind[j] - 1]
	if t > 0:
		print('TAK')
		print(*ind)
		exit()
print('NIE')


(n, m) = map(int, input().split())
t = [list(map(int, input().split())) for _ in range(n)]
for i in range(10):
	m = 1 << i
	is_zero = [all((i & m == 0 for i in row)) for row in t]
	is_one = [all((i & m != 0 for i in row)) for row in t]
	zero = is_zero.count(True)
	one = is_one.count(True)
	needed = 1 - one % 2
	ok = n - zero - one >= needed
	if not ok:
		continue
	print('TAK')
	for (y, row) in enumerate(t):
		if is_zero[y] or is_one[y]:
			print(1, end=' ')
			continue
		for (i, e) in enumerate(row):
			if needed and e & m != 0:
				print(i + 1, end=' ')
				needed -= 1
				break
			elif not needed and e & m == 0:
				print(i + 1, end=' ')
				break
	break
else:
	print('NIE')


(n, m) = map(int, input().split())
c = []
for i in range(n):
	c.append(list(map(int, input().split())))
nieflag = 1
for a in range(11):
	bit0row = 0
	bit1row = 0
	bit0rowlist = []
	bit1rowlist = []
	for i in range(n):
		bit1 = 0
		bit0 = 0
		for j in range(m):
			if c[i][j] % 2 == 1:
				bit1 += 1
			else:
				bit0 += 1
		if bit1 == m:
			bit1row += 1
			bit1rowlist.append(i)
		elif bit0 == m:
			bit0row += 1
			bit0rowlist.append(i)
	if bit1row == n and n % 2 == 0:
		for i in range(n):
			for j in range(m):
				c[i][j] //= 2
		continue
	elif bit0row == n:
		for i in range(n):
			for j in range(m):
				c[i][j] //= 2
		continue
	elif bit1row + bit0row == n and bit1row % 2 == 0:
		for i in range(n):
			for j in range(m):
				c[i][j] //= 2
		continue
	else:
		nieflag = 0
		break
if nieflag == 1:
	print('NIE')
else:
	print('TAK')
	ans = []
	if bit1row % 2 == 1:
		for i in range(n):
			if i in bit1rowlist:
				ans.append(1)
			elif i in bit0rowlist:
				ans.append(1)
			else:
				for j in range(m):
					if c[i][j] % 2 == 0:
						ans.append(j + 1)
						break
	else:
		flag = 0
		for i in range(n):
			if i in bit1rowlist:
				ans.append(1)
			elif i in bit0rowlist:
				ans.append(1)
			elif flag == 1:
				for j in range(m):
					if c[i][j] % 2 == 0:
						ans.append(j + 1)
						break
			else:
				for j in range(m):
					if c[i][j] % 2 == 1:
						ans.append(j + 1)
						flag = 1
						break
	print(' '.join(map(str, ans)))


import sys
(N, M) = map(int, input().split())
mat = [list(map(int, input().split())) for i in range(N)]

def db(*arg):
	print(*arg)
for i in range(10):
	column_1 = [-1] * N
	column_0 = [-1] * N
	flag_double = [0] * N
	count_only_1 = 0
	count_only_0 = 0
	count_double = 0
	for r in range(N):
		(found1, found0) = (False, False)
		for c in range(M):
			if mat[r][c] >> i & 1:
				column_1[r] = c
				found1 = True
			else:
				column_0[r] = c
				found0 = True
		if found0 and found1:
			flag_double[r] = 1
			count_double += 1
		elif found0:
			count_only_0 += 1
		else:
			count_only_1 += 1
	if not (count_double > 0 or count_only_1 % 2 == 1):
		continue
	ans_ls = [0] * N
	if count_only_1 % 2 == 1:
		for r in range(N):
			if flag_double[r] == 1:
				ans_ls[r] = column_0[r] + 1
			elif column_0[r] != -1:
				ans_ls[r] = column_0[r] + 1
			else:
				ans_ls[r] = column_1[r] + 1
	else:
		done = False
		for r in range(N):
			if flag_double[r] == 1:
				if not done:
					ans_ls[r] = column_1[r] + 1
					done = True
				else:
					ans_ls[r] = column_0[r] + 1
			elif column_0[r] != -1:
				ans_ls[r] = column_0[r] + 1
			else:
				ans_ls[r] = column_1[r] + 1
	print('TAK')
	print(*ans_ls)
	xor = mat[0][ans_ls[0] - 1]
	for i in range(1, N):
		xor ^= mat[i][ans_ls[i] - 1]
	assert xor > 0
	sys.exit()
print('NIE')


(n, m) = map(int, input().split())
arr = []
ans = 0
for i in range(n):
	k = list(map(int, input().split()))
	ans ^= k[0]
	arr.append(k)
ind = [0] * n
if ans == 0:
	for i in range(n):
		for j in range(1, m):
			ans ^= arr[i][0]
			ans ^= arr[i][j]
			if ans:
				ind[i] = j
				break
			else:
				ans ^= arr[i][j]
				ans ^= arr[i][0]
		if ind[i] != 0:
			break
if ans:
	print('TAK')
	for i in range(n):
		print(ind[i] + 1, end=' ')
else:
	print('NIE')


(n, m) = map(int, input().split())
x = 0
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
	x ^= l[i][0]
if x != 0:
	print('TAK')
	print('1 ' * n)
else:
	t = False
	ans = [1] * n
	for i in range(n):
		for j in range(m):
			if x ^ l[i][0] ^ l[i][j] != 0:
				print('TAK')
				ans[i] = j + 1
				print(*ans)
				t = True
				break
		if t:
			break
	else:
		print('NIE')


(n, m) = map(int, input().split())
dp = [[int(i) for i in input().split()] for j in range(n)]
res = 0
for i in range(n):
	res ^= dp[i][0]
if res:
	print('TAK')
	print(*[1] * n)
else:
	resa = [1] * n
	for i in range(n):
		for j in range(m):
			if dp[i][0] != dp[i][j]:
				resa[i] = j + 1
				print('TAK')
				print(*resa)
				exit()
	print('NIE')


(n, m) = map(int, input().split())
mat = []
for i in range(n):
	l = [int(i) for i in input().split()]
	mat.append(l)
ans = []
xor = 0
for i in mat:
	xor ^= i[0]
	ans.append(1)
if xor:
	print('TAK')
	print(*ans)
	exit()
else:
	for i in range(n):
		for j in range(m):
			if mat[i][j] ^ mat[i][0] > 0:
				ans[i] = j + 1
				print('TAK')
				print(*ans)
				exit()
print('NIE')


(n, m) = map(int, input().split())
a = []
for _ in range(n):
	a.append(list(map(int, input().split())))
for k in range(11):
	b = [[0 for _ in range(m)] for _ in range(n)]
	for i in range(n):
		for j in range(m):
			b[i][j] = 1 if a[i][j] & 1 << k > 0 else 0
	c = []
	for i in range(n):
		s = set()
		for j in range(m):
			s.add(b[i][j])
		c.append(s)
	oo = []
	oz = []
	zz = []
	for i_ in range(n):
		i = c[i_]
		if 1 in i and 0 not in i:
			oo.append(i_)
		if 1 in i and 0 in i:
			oz.append(i_)
		if 1 not in i and 0 in i:
			zz.append(i_)
	r = [0 for _ in range(n)]
	if len(oo) % 2 == 1:
		for i in oo:
			r[i] = b[i].index(1) + 1
		for i in oz:
			r[i] = b[i].index(0) + 1
		for i in zz:
			r[i] = b[i].index(0) + 1
	elif len(oz) > 0:
		for i in oo:
			r[i] = b[i].index(1) + 1
		x = False
		for i in oz:
			if not x:
				r[i] = b[i].index(1) + 1
				x = True
				continue
			r[i] = b[i].index(0) + 1
		for i in zz:
			r[i] = b[i].index(0) + 1
	else:
		continue
	if 0 in r:
		continue
	print('TAK')
	print(*r)
	import sys
	sys.exit(0)
print('NIE')


(n, m) = [int(i) for i in input().split()]
ls = []
for i in range(n):
	ls.append([int(i) for i in input().split()])
ans = 0
for i in range(n):
	ans ^= ls[i][0]
res = []
if ans != 0:
	res = [1 for i in range(n)]
else:
	for i in range(n):
		for j in range(m):
			if ls[i][0] != ls[i][j]:
				res += [1 for k in range(i)]
				res.append(j + 1)
				res += [1 for k in range(i + 1, n)]
				break
		if len(res) > 0:
			break
if len(res) == 0:
	print('NIE')
else:
	print('TAK')
	for i in res:
		print(i, end=' ')
	print('')


(n, m) = list(map(int, input().split()))
matrix = []
for _ in range(n):
	matrix.append(list(map(int, input().split())))
init_xor = 0
for i in range(n):
	init_xor ^= matrix[i][0]
ok = False
if init_xor > 0:
	print('TAK')
	print(*[1 for i in range(n)])
	ok = True
else:
	for i in range(n):
		if ok:
			break
		for j in range(1, m):
			if matrix[i][j] != matrix[i][0]:
				ans = [1 for i in range(n)]
				ans[i] = j + 1
				print('TAK')
				print(*ans)
				ok = True
				break
if not ok:
	print('NIE')


def solve():
	(N, M) = map(int, input().split())
	matrix = []
	ans = 0
	result = [1] * N
	for _ in range(N):
		matrix.append([int(k) for k in input().split()])
		ans ^= matrix[-1][0]
	col = 0
	while col < N and (not ans):
		for i in range(1, M):
			ans ^= matrix[col][i - 1]
			ans ^= matrix[col][i]
			if ans > 0:
				result[col] = i + 1
				break
		col += 1
	if ans == 0:
		print('NIE')
		return
	print('TAK')
	print(' '.join((str(k) for k in result)))
solve()


(n, m) = map(int, input().strip().split())
arr = []
for i in range(n):
	arr.append(list(map(int, input().strip().split())))
xor = 0
flag = 0
ele = []
for i in range(n):
	seti = set(arr[i])
	if len(seti) > 1 and flag == 0:
		flag = 1
		ele = [seti.pop(), seti.pop(), i]
	else:
		xor ^= arr[i][0]
if flag == 0 and xor == 0:
	print('NIE')
else:
	print('TAK')
	ans = [1 for i in range(n)]
	if flag == 1:
		ans[ele[2]] = arr[ele[2]].index(ele[0]) + 1 if xor ^ ele[0] is not 0 else arr[ele[2]].index(ele[1]) + 1
	print(*ans)


(n, m) = map(int, input().split())
lis = []
b = False
for i in range(n):
	l = list(map(int, input().split()))
	lis.append(l)
	if len(set(l)) > 1:
		b = True
		tmpList = l
		tmp = list(set(l))
		sql = l[0]
		mg = i
if not b:
	x = 0
	for i in lis:
		x = x ^ i[0]
	if x == 0:
		print('NIE')
	else:
		print('TAK')
		print(*[1 for _ in range(n)])
else:
	print('TAK')
	x = 0
	res = []
	for i in range(n):
		if i != mg:
			x ^= lis[i][0]
			res.append(1)
		else:
			res.append(0)
	if x ^ tmp[1] > 0:
		res[res.index(0)] = tmpList.index(tmp[1]) + 1
	else:
		res[res.index(0)] = tmpList.index(tmp[0]) + 1
	print(*res)


(m, n) = [int(x) for x in input().split()]

def is_solution(solution):
	from functools import reduce
	return reduce(lambda S, a: S ^ a[1], solution, 0) > 0
solution = [] * m
multiple_elements_row = None
for row in range(m):
	elements = [int(x) for x in input().split()]
	elements_dict = dict(((x, i) for (i, x) in enumerate(elements)))
	solution.append((0, elements[0]))
	if multiple_elements_row is None and len(elements_dict) > 1:
		multiple_elements_row = (row, elements_dict)
if multiple_elements_row is not None:
	(row, elements_dict) = multiple_elements_row
	while not is_solution(solution) and len(elements_dict) > 0:
		test_element = next(iter(elements_dict.keys()))
		test_element_position = elements_dict.pop(test_element)
		solution[row] = (test_element_position, test_element)
if is_solution(solution):
	print('TAK')
	print(' '.join((str(pos + 1) for (pos, _) in solution)))
else:
	print('NIE')


(n, m) = map(int, input().strip().split())
matrix = []
for i in range(n):
	x = list(map(int, input().strip().split()))
	matrix.append(x)
output = matrix[0][0]
for i in range(1, n):
	output ^= matrix[i][0]
if output == 0:
	isans = False
	for i in range(n):
		for j in range(1, len(matrix[i])):
			if output ^ matrix[i][0] ^ matrix[i][j] != 0:
				r = i
				c = j
				isans = True
				break
	if isans:
		print('TAK')
		for i in range(n):
			if i != r:
				print('1', end=' ')
			else:
				print(c + 1, end=' ')
	else:
		print('NIE')
else:
	print('TAK')
	for i in range(n):
		print('1', end=' ')


l = input().split()
n = int(l[0])
m = int(l[1])
lfi = []
for i in range(n):
	l = input().split()
	li = [int(i) for i in l]
	lfi.append(li)
xori = 0
for i in range(n):
	xori = xori ^ lfi[i][0]
if xori != 0:
	print('TAK')
	for i in range(n):
		print(1, end=' ')
	print()
	quit()
done = 0
arr = [1 for i in range(n)]
for i in range(n):
	for j in range(m):
		if lfi[i][j] != lfi[i][0]:
			done = 1
			arr[i] = j + 1
			break
	if done:
		break
if done:
	print('TAK')
	for i in range(n):
		print(arr[i], end=' ')
	quit()
print('NIE')


def myXOR(x, y):
	res = 0
	for i in range(31, -1, -1):
		b1 = x & 1 << i
		b2 = y & 1 << i
		b1 = min(b1, 1)
		b2 = min(b2, 1)
		xoredBit = 0
		if b1 & b2:
			xoredBit = 0
		else:
			xoredBit = b1 | b2
		res <<= 1
		res |= xoredBit
	return res

def XOR(lst, index=0):
	if lst == []:
		return 0
	if index == len(lst) - 1:
		return lst[-1]
	else:
		return myXOR(lst[index], XOR(lst, index + 1))
[m, n] = [int(i) for i in input().split()]
row = None
lst = []
for i in range(m):
	r = [int(j) for j in input().split()]
	lst.append(r)
	if len(set(r)) > 1:
		row = i
if row is None:
	if XOR([i[0] for i in lst]):
		print('TAK')
		print('1 ' * m)
	else:
		print('NIE')
else:
	num = XOR([lst[i][0] for i in range(m) if i != row])
	print('TAK')
	for i in range(n):
		if myXOR(lst[row][i], num):
			print('1 ' * row, end='')
			print(i + 1, end=' ')
			print('1 ' * (m - row - 1), end='')
			break
	print()