loop do
  m = gets.to_i
  break if m.zero?
  m.times.map do
    id, *ss = gets.split
    ss.map!(&:to_i)
    s, i = 0, 0
    10.times do |j|
      if ss[i] == 10
        s += ss[i] + ss[i+1] + ss[i+2]
        i += 1
      elsif ss[i] + ss[i+1] == 10
        s += ss[i] + ss[i+1] + ss[i+2]
        i += 2
      else
        s += ss[i] + ss[i+1]
        i += 2
      end
    end
    [-s, id]
  end.sort!.each {|s, id| puts "#{id} #{-s}" }
end