until (n = gets.chomp.to_i) == 0
  score_ary = []
  n.times do
    ary = gets.split.map(&:to_i)
    score_ary << ary.shift
    tmp_ary = []
    pin_ary = []
    tmp = 0
    ary.each_with_index do |item, index|
      tmp_ary << item
      if tmp_ary.size == 2 or tmp_ary[0] == 10
        pin_ary << tmp_ary
        tmp_ary = []
      end
      if pin_ary.size == 9
        tmp = index
        break
      end
    end
    pin_ary << ary.slice((tmp + 1)..(ary.size - 1))
    tmp_score = []
    pin_ary.each_with_index do |item, index|
      if index < 8
        if item[0] == 10
          if pin_ary[index + 1].size == 2
            tmp = 10 + pin_ary[index + 1][0] + pin_ary[index + 1][1]
          else
            tmp = 10 + pin_ary[index + 1][0] + pin_ary[index + 2][0]
          end
        elsif item[0] + item[1] == 10
          tmp = 10 + pin_ary[index + 1][0]
        else
          tmp = item[0] + item[1]
        end
      elsif index == 8
        if item[0] == 10
          tmp = 10 + pin_ary[index + 1][0] + pin_ary[index + 1][1]
        elsif item[0] + item[1] == 10
          tmp = 10 + pin_ary[index + 1][0]
        else
          tmp = item[0] + item[1]
        end
      else
        tmp = item.inject(:+)
      end
      tmp_score << tmp
    end
    score_ary << tmp_score.inject(:+)
  end
  Hash[*score_ary].sort_by {|k, v| -v}.each {|item| puts item.join(" ")}
end