problem

One day, Taro, who lives in JOI town, decided to take a walk as a daily routine to improve his health. In JOI town, where Taro lives, he runs in the east-west direction as shown in the figure (H + 1). The road and the north-south direction (W + 1) run through the road in a grid pattern. Taro's house is at the northwestern intersection, and the walk starts from here.

Hereafter, the ath intersection from the north and the bth intersection from the west are represented by (a, b). For example, the intersection where Taro's house is located is (1, 1).


<image>

Figure: JOI town map (for H = 3, W = 4). The top of the figure corresponds to the north and the left corresponds to the west.

Taro thought that it would be more interesting if the walking route was different every day, so he wrote the letters "east" or "south" at the H x W intersections from (1, 1) to (H, W). , I decided to take a walk every day according to the following rules.

* If you are at an intersection with letters, rewrite the letters from "east" to "south" and "south" to "east", and the direction of the originally written letters. Proceed to the next intersection at.
* End the walk when you reach the easternmost or southernmost road.



After thinking about this plan, Taro was wondering what route he would take in his future walks. For Taro, he predicted the route for Taro's Nth walk. Create a program to do.



input

The input consists of multiple datasets. Each dataset is given in the following format.

On the first line, three positive integers are separated by blanks. These are the values ​​of the three numbers H, W, N in the problem statement. H, W, N are 1 ≤ H ≤, respectively. 1000, 1 ≤ W ≤ 1000, 1 ≤ N ≤ 10000000 = 107. From the 2nd line to H + 1st line, W integers are written separated by blanks. Represents the information of the character written at the intersection first. If the jth integer of i + 1st line is 0, the character written at the intersection (i, j) is "south", and if it is 1, the intersection Indicates that the character written in (i, j) is "east".

Of the scoring data, 30% of the points are satisfied with H ≤ 100, W ≤ 100, and N ≤ 1000.

When H, W, N are all 0, it indicates the end of input. The number of data sets does not exceed 10.

output

Output in the following format for each data set.
When the intersection where Taro finishes the walk in the Nth walk is (i, j), output i and j separated by a blank in this order.

Example

Input

3 4 3
1 0 1 1
0 1 0 0
1 0 1 0
0 0 0


Output

1 5

Source: aizu | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
import string
import sys
from itertools import chain, takewhile

def read(f, *shape, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)):

	def read_word():
		return f(''.join(takewhile(lambda c: c not in whitespaces, it)).strip())
	if not shape:
		return read_word()
	elif len(shape) == 1:
		return [read_word() for _ in range(shape[0])]
	elif len(shape) == 2:
		return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]

def arr(*shape, fill_value=0):
	if len(shape) == 1:
		return [fill_value] * shape[fill_value]
	elif len(shape) == 2:
		return [[fill_value] * shape[1] for _ in range(shape[0])]

def debug(**kwargs):
	print(', '.join(('{} = {}'.format(k, repr(v)) for (k, v) in kwargs.items())), file=sys.stderr)

def main():
	while True:
		(h, w, n) = map(int, sys.stdin.readline().split())
		if (h, w, n) == (0, 0, 0):
			return
		grid = []
		for _ in range(h):
			row = list(map(int, sys.stdin.readline().split()))
			grid.append(row)
		dp = arr(h, w)
		dp[0][0] = n - 1
		for i in range(h):
			for j in range(w):
				if i < h - 1 and grid[i][j] == 0:
					dp[i + 1][j] += (dp[i][j] + 1) // 2
				if i < h - 1 and grid[i][j] == 1:
					dp[i + 1][j] += dp[i][j] // 2
				if j < w - 1 and grid[i][j] == 0:
					dp[i][j + 1] += dp[i][j] // 2
				if j < w - 1 and grid[i][j] == 1:
					dp[i][j + 1] += (dp[i][j] + 1) // 2
		for i in range(h):
			for j in range(w):
				grid[i][j] = (grid[i][j] + dp[i][j]) % 2
		i = 0
		j = 0
		while i < h and j < w:
			if grid[i][j] == 0:
				i += 1
			else:
				j += 1
		print(i + 1, j + 1)
main()


def solve():
	while True:
		(h, w, n) = map(int, input().split())
		if not h:
			break
		sss = [[1 if s == '1' else 0 for s in input().split()] for i in range(h)]
		dp = [[0 for i in range(w + 1)] for j in range(h + 1)]
		dp[0][0] = n - 1
		for x in range(h):
			for y in range(w):
				a = dp[x][y]
				b = sss[x][y]
				if b:
					if a % 2:
						dp[x + 1][y] += a // 2
						dp[x][y + 1] += a // 2 + 1
					else:
						dp[x + 1][y] += a // 2
						dp[x][y + 1] += a // 2
				elif a % 2:
					dp[x + 1][y] += a // 2 + 1
					dp[x][y + 1] += a // 2
				else:
					dp[x + 1][y] += a // 2
					dp[x][y + 1] += a // 2
				sss[x][y] = (a + b) % 2
		x = y = 0
		while x < h and y < w:
			if sss[x][y]:
				y += 1
			else:
				x += 1
		print(x + 1, y + 1)
solve()


while True:
	(h, w, n) = map(int, input().split())
	if not h:
		break
	sss = [[1 if s == '1' else 0 for s in input().split()] for i in range(h)]
	dp = [[0 for i in range(w + 1)] for j in range(h + 1)]
	dp[0][0] = n - 1
	for x in range(h):
		for y in range(w):
			a = dp[x][y]
			if sss[x][y]:
				if a % 2:
					dp[x + 1][y] += a // 2
					dp[x][y + 1] += a // 2 + 1
				else:
					dp[x + 1][y] += a // 2
					dp[x][y + 1] += a // 2
			elif a % 2:
				dp[x + 1][y] += a // 2 + 1
				dp[x][y + 1] += a // 2
			else:
				dp[x + 1][y] += a // 2
				dp[x][y + 1] += a // 2
			sss[x][y] = (sss[x][y] + dp[x][y]) % 2
	x = y = 0
	while x < h and y < w:
		if sss[x][y]:
			y += 1
		else:
			x += 1
	print(x + 1, y + 1)


while True:
	(h, w, n) = map(int, input().split())
	if h == 0:
		break
	mapp = []
	for i in range(h):
		hoge = list(map(int, input().split()))
		hoge.append(0)
		mapp.append(hoge)
	mapp.append([0] * (w + 1))
	n -= 1
	nmap = [[0] * (w + 1) for _ in range(h + 1)]
	nmap[0][0] = n
	for i in range(h):
		for j in range(w):
			nmap[i + 1][j] += (nmap[i][j] + 1 - mapp[i][j]) // 2
			nmap[i][j + 1] += (nmap[i][j] + mapp[i][j]) // 2
			mapp[i][j] = (nmap[i][j] + mapp[i][j]) % 2
	(i, j) = (0, 0)
	while i < h and j < w:
		if mapp[i][j] == 0:
			i += 1
		else:
			j += 1
	print(i + 1, j + 1)


def main():
	while True:
		import sys
		input = sys.stdin.readline
		(h, w, n) = map(int, input().split())
		if h == 0:
			break
		grid = [list(map(int, input().split())) for _ in [0] * h]
		dp = [[0] * (w + 1) for _ in [0] * (h + 1)]
		dp[0][0] = n - 1
		for k in range(h + w - 1):
			for i in range(max(0, k - w + 1), min(h, k + 1)):
				j = k - i
				x = dp[i][j]
				if grid[i][j] == 1:
					dp[i + 1][j] += x // 2
					dp[i][j + 1] += x - x // 2
				else:
					dp[i][j + 1] += x // 2
					dp[i + 1][j] += x - x // 2
		for i in range(h):
			for j in range(w):
				dp[i][j] = (grid[i][j] + dp[i][j]) % 2
		(i, j) = (1, 1)
		while True:
			if dp[i - 1][j - 1] == 1:
				j += 1
			else:
				i += 1
			if i > h or j > w:
				break
		print(i, j)
main()


import sys

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')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
while True:
	(H, W, N) = MAP()
	if H == W == H == 0:
		break
	grid = list2d(H, W, 0)
	for i in range(H):
		row = LIST()
		for j in range(W):
			grid[i][j] = row[j]
	dp = list2d(H + 1, W + 1, 0)
	dp[0][0] = N - 1
	for i in range(H):
		for j in range(W):
			if dp[i][j] % 2 == 0:
				dp[i + 1][j] += dp[i][j] // 2
				dp[i][j + 1] += dp[i][j] // 2
			elif grid[i][j] == 0:
				dp[i + 1][j] += dp[i][j] // 2 + 1
				dp[i][j + 1] += dp[i][j] // 2
			else:
				dp[i + 1][j] += dp[i][j] // 2
				dp[i][j + 1] += dp[i][j] // 2 + 1
	for i in range(H):
		for j in range(W):
			grid[i][j] ^= dp[i][j]
			grid[i][j] &= 1
	i = j = 0
	while i < H and j < W:
		if grid[i][j] == 0:
			i += 1
		else:
			j += 1
	print(i + 1, j + 1)


def solve():
	while True:
		(h, w, n) = map(int, input().split())
		if not h:
			break
		sss = [[1 if s == '1' else 0 for s in input().split()] for i in range(h)]
		dp = [[0 for i in range(w + 1)] for j in range(h + 1)]
		dp[0][0] = n - 1
		for x in range(h):
			for y in range(w):
				a = dp[x][y]
				if sss[x][y]:
					if a % 2:
						dp[x + 1][y] += a // 2
						dp[x][y + 1] += a // 2 + 1
					else:
						dp[x + 1][y] += a // 2
						dp[x][y + 1] += a // 2
				elif a % 2:
					dp[x + 1][y] += a // 2 + 1
					dp[x][y + 1] += a // 2
				else:
					dp[x + 1][y] += a // 2
					dp[x][y + 1] += a // 2
				sss[x][y] = (sss[x][y] + dp[x][y]) % 2
		x = y = 0
		while x < h and y < w:
			if sss[x][y]:
				y += 1
			else:
				x += 1
		print(x + 1, y + 1)
solve()


def solve():
	while True:
		(h, w, n) = map(int, input().split())
		if not h:
			break
		mp = [[int(s) for s in input().split()] for i in range(h)]
		dp = [[0 for i in range(w + 1)] for j in range(h + 1)]
		dp[0][0] = n - 1
		for x in range(h):
			dpx = dp[x]
			dpxp = dp[x + 1]
			mpx = mp[x]
			for y in range(w):
				a = dpx[y]
				b = mpx[y]
				if b:
					if a % 2:
						dpxp[y] += a // 2
						dpx[y + 1] += a // 2 + 1
					else:
						dpxp[y] += a // 2
						dpx[y + 1] += a // 2
				elif a % 2:
					dpxp[y] += a // 2 + 1
					dpx[y + 1] += a // 2
				else:
					dpxp[y] += a // 2
					dpx[y + 1] += a // 2
				mpx[y] = (a + b) % 2
		x = y = 0
		while x < h and y < w:
			if mp[x][y]:
				y += 1
			else:
				x += 1
		print(x + 1, y + 1)
solve()