import heapq
que = []
N = 30
A = [list(map(int, input().split())) for _ in range(N)]
for i in range(N):
for j in range(N):
heapq.heappush(que, (-A[i][j], i, j))
dire = [(0, 1), (1, 0), (0, -1), (-1, 0)]
def eval(a, x, y):
if a == 0:
return 0
v = 0
for dx, dy in dire:
if 0<=x+dx<N and 0<=y+dy<N:
if A[x+dx][y+dy] == a:
v+=1
return v
def search(a, x, y):
if a == 0:
return
candidate = []
for dx, dy in dire:
if 0<=x+dx<N and 0<=y+dy<N:
if A[x+dx][y+dy] == a:
candidate.append((eval(a-1, x+dx, y+dy), x+dx, y+dy))
if not candidate:
return
v, x, y = max(candidate)
print(x+1, y+1)
search(a-1, x, y)
return
while que:
a, i, j = heapq.heappop(que)
a = -a
if A[i][j] != a:
if A[i][j]>0:
heapq.heappush(que, (-A[i][j], i, j))
continue
print(i+1, j+1)
a-=1
A[i][j]-=1
search(a, i, j)
if a>0:
heapq.heappush(que, (-a, i, j))