#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
class Record{
public:
string school;
double scores;
int num;
// int rank;
bool operator < (Record const a){
if(scores==a.scores)
{
if(num==a.num)return school<a.school;
else return num<a.num;
}
else return scores>a.scores;
}
};
string func(string str)
{
for(int i=0;i<str.size();++i)
{
if(str[i]>='A'&&str[i]<='Z') str[i]=str[i]-'A'+'a';
}
return str;
}
int main()
{
map<string,int> schoolhash;
vector<Record> records;
int n;
int k=0;
cin>>n;
for(int i=0;i<n;++i)
{
string ID,school;
int score;
cin>>ID>>score>>school;
school = func(school);
map<string,int>::iterator it = schoolhash.find(school);
if(it==schoolhash.end())
{
schoolhash[school] = k++;
Record tmp;
tmp.school = school;
double w = 1;
if(ID[0]=='B') w = 1/1.5;
if(ID[0]=='T') w = 1.5;
tmp.scores = score*w;
tmp.num = 1;
records.push_back(tmp);
}
else
{
int t = schoolhash[school];
records[t].num++;
double w = 1;
if(ID[0]=='B') w = 1/1.5;
if(ID[0]=='T') w = 1.5;
records[t].scores+=score*w;
}
}
for(int i=0;i<records.size();++i)
{
records[i].scores = int(records[i].scores);
}
sort(records.begin(),records.end());
int rank=1;
cout<<records.size()<<endl;
while(rank<=records.size())
{
int i = rank;
cout<<rank<<" "<<records[i-1].school<<" "<<records[i-1].scores<<" "<<records[i-1].num<<endl;
while(i<records.size()&&records[i-1].scores==records[i].scores) {
cout<<rank<<" "<<records[i].school<<" "<<records[i].scores<<" "<<records[i].num<<endl;
++i;
}
rank=i+1;
}
return 0;
}