n = gets.to_i

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

drops = []
0.upto(n){|k|
  break if 13 * k > num
  0.upto(n-k){|j|
    break if 9*j + 13 * k > num
    i = n - j - k
    if 5 * i + 9 * j + 13 * k == num
      drops << [i, j, k]
    end
  }
}

s = [[0,0],[1,0],[-1,0],[0,1],[0,-1]]
m = [[1,1],[1,-1],[-1,1],[-1,-1]]
l = [[2,0],[-2,0],[0,2],[0,-2]]

candidate = [[],[],[]]
1.upto(8){|i|
  1.upto(8){|j|
    flag = 2
    l.each{|dx, dy|
      if j+dy < 0 || 9 < j+dy || i+dx < 0 || 9 < i+dx || mat[j+dy][i+dx] == 0
        flag = 1
      end
    }
    m.each{|dx, dy|
      if mat[j+dy][i+dx] == 0
        flag = 0
        break
      end
    }
    s.each{|dx, dy|
      if mat[j+dy][i+dx] == 0
        flag = -1
        break
      end
    }
    if flag > -1
      candidate[flag] << [i, j]
    end
  }
}

drops.each{|i, j, k|
  next if candidate[0].size < i || candidate[1].size < j || candidate[2].size < k
  candidate[2].combination(k).to_a.each{|a1|
    mat1 = Array.new(10){Array.new(10){0}}
    a1.each{|x, y|
      l.each{|dx, dy|
        mat1[y+dy][x+dx] += 1
      }
    }
    (candidate[1] + candidate[2] - a1).combination(j).to_a.each{|a2|
      mat2 = mat1.map(&:dup)
      (a1+a2).each{|x, y|
        m.each{|dx, dy|
          mat2[y+dy][x+dx] += 1
        }
      }
      (candidate[0] + candidate[1] + candidate[2] - a1 - a2).combination(i).to_a.each{|a3|
        mat3 = mat2.map(&:dup)
        (a1+a2+a3).each{|x, y|
          s.each{|dx, dy|
            mat3[y+dy][x+dx] += 1
          }
        }
        if mat == mat3
          a1.each{|x, y|
            puts "#{x} #{y} 3"
          }
          a2.each{|x, y|
            puts "#{x} #{y} 2"
          }
          a3.each{|x, y|
            puts "#{x} #{y} 1"
          }
          exit
        end
      }
    }
  }
}