#include <bits/stdc++.h>

using namespace std;

vector<int> stovi(string s){
    vector<int> ret;
    int t=0;
    for (int i = 1; i < s.size(); ++i) {
        if(isdigit(s[i])){
            t=t*10;
            t+=s[i]-'0';
        }
        else {
            ret.emplace_back(t);
            t=0;
        }
    }
    ret.emplace_back(t);
    return ret;
}

int calscore(string s){
    vector<int> scores=stovi(s);
    int ret=0;
    int flame=1;
    bool first=true;
    bool spare=false;
    bool strike=false;
    bool strike2=false;
    for (int i = 0; i < scores.size(); ++i) {
        ret+=scores[i];
        if(spare)ret+=scores[i];
        if(strike)ret+=scores[i];
        if(strike2)ret+=scores[i];
        strike2=strike;
        strike=false;
        spare=false;
        if(first){
            if(flame!=10&&scores[i]==10){
                strike=true;
                ++flame;
            }
            else first=false;
        }
        else{
            if(flame!=10&&scores[i]+scores[i-1]==10)spare=true;
            first=true;
            ++flame;
        }
    }
    return ret;
}

int main(){
    int n;
    while(true){
        cin>>n;
        if(n==0)break;
        vector<pair<int,int>> sc;
        for (int i = 0; i < n; ++i) {
            int id;
            string s;
            cin>>id;
            getline(cin,s);
            sc.emplace_back(calscore(s),-id);
        }
        sort(sc.rbegin(),sc.rend());
        for(auto i:sc)cout<<-i.second<<" "<<i.first<<endl;
    }
    return 0;
}
