#include<iostream>
#include<algorithm>
using namespace std;
struct Team {
int score, time;
string name;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
Team teams[n];
for (int i = 0; i < n; i++) {
string s;
cin >> s;
int time = 0, score = 0;
for (int i = 0; i < 10; i++) {
char c;
cin >> c;
if (c == 'A') {
int x;
cin >> x;
time += x;
score++;
}
}
teams[i] = {score, time, s};
}
sort(teams, teams + n, [](const auto & a, const auto & b) {
if (a.score != b.score) return a.score > b.score;
else if (a.time != b.time) return a.time < b.time;
else return a.name < b.name;
});
for_each(teams, teams + n,
[](const auto & team) {
cout << team.name << ' ' << team.score << ' ' << team.time << endl;
});
return 0;
}