L = [[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]]
M = [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]]
S = [[0,0],[1,-1],[1,0],[1,1],[2,0]]

def rev_drop(mat, drops, n)
  return false if drops.size > n
  10.times{|y|
    10.times{|x|
      if mat[y][x] > 0
        # p [x, y]
        flag = true
        nmat=mat.map(&:dup)
        L.each{|dy, dx|
          if y+dy<0 || 9<y+dy || x+dx<0 || 9<x+dx || nmat[y+dy][x+dx] == 0
            flag = false
            break
          end
          nmat[y+dy][x+dx] -= 1
        }
        if flag
          return true if rev_drop(nmat, drops + [[x, y+2, 3]], n)
        end
        flag = true
        nmat=mat.map(&:dup)
        M.each{|dy, dx|
          if y+dy<0 || 9<y+dy || x+dx<0 || 9<x+dx || nmat[y+dy][x+dx] == 0
            flag = false
            break
          end
          nmat[y+dy][x+dx] -= 1
        }
        if flag
          return true if rev_drop(nmat, drops + [[x+1, y+1, 2]], n)
        end
        flag = true
        nmat=mat.map(&:dup)
        S.each{|dy, dx|
          if y+dy<0 || 9<y+dy || x+dx<0 || 9<x+dx || nmat[y+dy][x+dx] == 0
            flag = false
            break
          end
          nmat[y+dy][x+dx] -= 1
        }
        if flag
          return true if rev_drop(nmat, drops + [[x, y+1, 1]], n)
        end
        return false
      end
    }
  }
  drops.each{|drop|
    puts drop.join(" ")
  }
  return true
end

n = gets.to_i

mat = []
10.times{|i|
  mat[i] = gets.split.map(&:to_i)
}

rev_drop(mat, [], n)