H = W = 10
Blur = [
  [[0,0], [1,-1], [1,0], [1,1], [2,0]],
  [[0,0], [0,1], [0,2], [1,0], [1,1], [1,2], [2,0], [2,1], [2,2]],
  [[0,0], [1,-1], [1,0], [1,1], [2,-2], [2,-1], [2,0], [2,1], [2,2], [3,-1], [3,0], [3,1], [4,0]],
]
Small, Medium, Large = 0, 1, 2
Y, X = 0, 1

def solve(cloth)
  @answer = Array.new
  dfs(cloth, 0, 0, 0)
  @answer
end

def dfs(cloth, y, x, depth)
  for ny in 0...H do
    for nx in 0...W do
      break if cloth[ny][nx] != 0
    end
    break if cloth[ny][nx] != 0
  end
  return true if ny==H-1 && nx==W-1 && cloth[ny][nx]==0 && @ink==depth
  return false if ny<y || (ny==y && nx<x)
  for b in 0...Blur.size do
    ok = true
    c = cloth.map(&:dup)
    Blur[b].each do |d|
      i = ny+d[Y]
      j = nx+d[X]
      if i<0 || H<=i || j<0 || W<=j || cloth[i][j]==0
        ok = false
        break
      end
      c[i][j] -= 1
    end
    next unless ok
    if dfs(c, ny, nx, depth+1)
      case b
        when Small
          @answer.push([nx, ny+1, 1])
        when Medium
          @answer.push([nx+1, ny+1, 2])
        when Large
          @answer.push([nx, ny+2, 3])
      end
      return true
    end
  end
  false
end

@ink = gets.to_i
cloth = Array.new
H.times do cloth.push(gets.split.map(&:to_i)) end
solve(cloth).each do |e|
  puts e*" "
end