#include <bits/stdc++.h>

using namespace std;

class StudentInfo {
public:
	int id, score;

	StudentInfo():score(0) {
	}
};

StudentInfo StuData[40];
int ScoreOfSet[21];

int calculation(int n) {
	int i, sum, cnt;

	i = sum = cnt = 0;
	while (cnt!=10)
	{
		//cout << "start:" << i;
		if (ScoreOfSet[i] == 10) {
			sum += 10 + ScoreOfSet[i + 1] + ScoreOfSet[i + 2];
			i++;
		}
		else if (ScoreOfSet[i] + ScoreOfSet[i+1] == 10) {
			sum += 10 + ScoreOfSet[i + 2];
			i += 2;
		}
		else {
			sum += ScoreOfSet[i] + ScoreOfSet[i + 1];
			i += 2;
		}
		//cout <<"   sum=" << sum << endl;
		cnt++;
	}
	return sum;
}



bool cmp(const StudentInfo &stu1, const StudentInfo &stu2) {
	if (stu1.score == stu2.score) {
		return stu1.id < stu2.id;
	}
	return stu1.score > stu2.score;
}

int main() {
	int n,j;
	string str;
	stringstream ss;

	while (cin >> n, n) {
		getchar();
		memset(ScoreOfSet, 0, sizeof(ScoreOfSet));
	
		for (int i = 0; i < n; i++) {
			j = 0;
			getline(cin, str);
			ss << str;
			ss >> StuData[i].id;
			while (ss) {
				ss >> ScoreOfSet[j++];
			}
			j--;
			StuData[i].score = calculation(j);
			ss.clear();
			str = "";
		}
		sort(StuData, StuData + n, cmp);
		
		for (int i = 0; i < n; i++) {
			cout << StuData[i].id << " " << StuData[i].score << endl;
		}
	}

	return 0;
}

