def read_data():
  n=input()
  x=[]
  for i in range(10): x.append(map(int,raw_input().split()))
  return n, x

def is_area3(x,y):
  if x>7 or y>5: return False
  for dx in [0,1,2,1,0]:
    A=P[y][x-dx:x+dx+1]
    if A.count(0)>0: return False
    y+=1
  return True
      
def is_area2(x,y):
  if x>7 or y>7: return False
  for dy in [0,1,2]:
    A=P[y+dy][x:x+3]
    if A.count(0)>0: return False
  return True

def is_area1(x,y):
  if x>8 or y>7: return False
  for dx in [0,1,0]:
    A=P[y][x-dx:x+dx+1]
    if A.count(0)>0: return False
    y+=1
  return True

def ink(x,y,s,m):
  global P
  dx = [0,1,-1,0,0,1,1,-1,-1,2,-2,0,0]
  dy = [0,0,-0,1,-1,1,-1,1,-1,0,0,2,-2]
  for i in range([5,9,13][s-1]): P[y+dy[i]][x+dx[i]]+=m
  return

drops,P = read_data()
A=[]
i=-1
m=3
while i<99:
  i+=1
  y=i/10
  x=i%10
  if P[y][x]==0: continue

  if m==3:
    while is_area3(x,y):
      A.append([x,y,3])
      ink(x,y+2,3,-1)
    if P[y][x]==0:
      m=3
      continue
    else: m=2

  if m==2:
    while is_area2(x,y):
      A.append([x,y,2])
      ink(x+1,y+1,2,-1)
    if P[y][x]==0:
      m=3
      continue
    else: m=1

  if m==1:
    while is_area1(x,y):
      A.append([x,y,1])
      ink(x,y+1,1,-1)
    if P[y][x]==0:
      m=3
      continue
    else: m=0

  dx=[0,1,0]
  dy=[1,1,2]
  if m==0 and len(A)>0:
    x,y,m=A.pop()
    m-=1
    ink(x+dx[m],y+dy[m],m+1,1)
    i = y*10+x-1
  else: break

if drops <=12 and len(A)==drops:
  for x,y,s in A: print x+dx[s-1],y+dy[s-1],s