while gets
    n=$_.to_i
    hash=Hash.new
    swich=0
    break if n==0
    n.times do
        arr=Array.new
        i=0
        k=1
        name,*a=gets.chomp.split.map(&:to_i)
        while a.size
            if k==10
                if a[i]==10||a[i+1]==10||(a[i]+a[i+1])==10
                    arr<<[a[i],a[i+1],a[i+2]]
                else
                    arr<<[a[i],a[i+1]]
                end
                break
            end
            if a[i]==10
                arr<<[10,0]
                k+=1
                i+=1
                swich+=1
                next
            end
            if  (swich%2)==0
                arr<<[a[i],a[i+1]]
                k+=1
                i+=2
            end
            if  (swich%2)==1
                arr<<[a[i],a[i+1]]
                k+=1
                i+=2
            end
        end
        hash[name]=0
        (arr.size).times do |i|
            (arr[i].size).times do |k|
                if arr[i][0]==10&&i!=9#????????????
                    if arr[i+1][0]==10&&i+2<=9
                        hash[name]+=20+arr[i+2][0]
                    else
                        hash[name]+=10+arr[i+1][0]+arr[i+1][1]
                    end
                    break
                end
                if (arr[i][0]+arr[i][1])==10&&i!=9#????????¢
                    hash[name]+=10+arr[i+1][0]
                    break
                end
                
                hash[name]+=arr[i][k]
            end
        end
    end
    p a=hash.sort{|(b1,b2),(c1,c2)|b2<=>c2}.reverse
    (a.size).times{|i|print a[i][0]," ",a[i][1],"\n"}
end