
def solve(p, s, list)
  result = Array.new
  while r=fill!(p, s, list) do
    result += r
  end
  list.each do |l|
    l.each do |v|
      return ["NO"] unless v
    end
  end
  result.sort{|a, b| a[0]!=b[0] ? a[0]<=>b[0] : (a[1]!=b[1] ? a[1]<=>b[1] : a[2]<=>b[2])}.collect{|v| v.last}
end

def fill!(p, s, list)
  result = Array.new
  p.times do |i|
    question = Array.new
    sum = 0
    s.times do |j|
      sum += list[i][j] if list[i][j]
      question.push(j) unless list[i][j]
    end
    next if question.size != 1
    list[i][question.first] = list[i].last - sum
    result.push([i, question.first, list[i][question.first]])
  end
  s.times do |j|
    question = Array.new
    sum = 0
    p.times do |i|
      sum += list[i][j] if list[i][j]
      question.push(i) unless list[i][j]
    end
    next if question.size != 1
    list [question.first][j] = list.last[j] - sum
    result.push([question.first, j, list [question.first][j]])
  end
  result.size.zero? ? nil : result
end

until (p,s=gets.split.map(&:to_i)).all?(&:zero?) do
  list = Array.new
  (p+1).times{list.push(gets.split.map{|v| v=="?" ? nil : v.to_i})}
  gets
  solve(p,s,list).each{|v| puts v}
  puts ""
end