Blur = [
  [ [0, 0], [-1, 1], [0, 1], [1, 1], [-2, 2], [-1, 2], [0, 2], [1, 2], [2, 2], [-1, 3], [0, 3], [1, 3], [0, 4] ],
  [ [0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2], ],
  [ [0, 0], [-1, 1], [0, 1], [1, 1], [0, 2] ]
]
Blur_sz = [5, 3, 3]
Blur_c = [[0, 2], [1, 1], [0, 1]]

def solve(fld, x, y, m)
  if m == $n
    if fld.flatten.all?{ |v| v == 0 }
      return true
    else return false
    end
  end

  3.times do |z|
    t = Blur_sz[z]
    10.times do |i|
      10.times do |j|
        if fld[i][j] > 0
          return false if i < y || i == y && j < x
          if ps = ok(j, i, z)
            if ps.all?{ |x, y| fld[y][x] > 0 }
              nfld = fld.map(&:dup)
              ps.each{ |x, y| nfld[y][x] -= 1 }
              $ans[m] = [j + Blur_c[z][0], i + Blur_c[z][1], 3 - z]
              return true if solve(nfld, j, i, m + 1)
            end
          end
        end
      end
    end
  end
  false
end

def ok(x, y, z)
  ret = []
  Blur[z].each do |c, r|
    nx = x + c; ny = y + r
    return false unless 0 <= nx && nx < 10 && 0 <= ny && ny < 10
    ret << [nx, ny]
  end
  ret
end

$n = gets.to_i
$ans = $n.times.map { [] }
fld = 10.times.map { gets.split.map(&:to_i) }
solve(fld, 0, 0, 0)
$ans.each{ |a| puts a.join(' ') }