Blur = [[0, 1, 0, 1, 1, 1, 0, 1, 0],
        [0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0]]

def solve(fld, m)
  if m == $n
    if fld.flatten.all?{ |v| v == 0 }
      return true
    else return false
    end
  end
  (0..5).each do |i|
    (0..5).each do |j|
      if fld[i,5].map{|f| f[j,5]}.flatten.zip(Blur[1]).all?{ |a, b| a - b >= 0 }
        old = fld.map{ |f| f.dup }
        (0..4).each do |k|
          (0..4).each do |l|
            fld[i+k][j+l] -= Blur[1][k * 5 + l]
          end
        end
        $ans[m] = [j+2, i+2, 3]
        return true if solve(fld, m + 1)
        fld = old.map{ |f| f.dup }
      end
    end
  end
  (0..7).each do |i|
    (0..7).each do |j|
      if fld[i,3].map{|f| f[j,3]}.flatten.all?{ |v| v > 0}
        old = fld.map{ |f| f.dup }
        (0..2).each do |k|
          (0..2).each do |l|
            fld[i+k][j+l] -= 1
          end
        end
        $ans[m] = [j+1, i+1, 2]
        return true if solve(fld, m + 1)
        fld = old.map{ |f| f.dup }
      end
    end
  end
  (0..7).each do |i|
    (0..7).each do |j|
      if fld[i,3].map{|f| f[j,3]}.flatten.zip(Blur[0]).all?{ |a, b| a - b >= 0 }
        old = fld.map{ |f| f.dup }
        (0..2).each do |k|
          (0..2).each do |l|
            fld[i+k][j+l] -= Blur[0][k * 3 + l]
          end
        end
        $ans[m] = [j+1, i+1, 1]
        return true if solve(fld, m + 1)
        fld = old.map {|f| f.dup }
      end
    end
  end
  false
end

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