#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
struct node{
string name;
int scoreB=0,scoreA=0,scoreT=0,tws=0,num=0;
int rrank;
};
map<string,node> school;
vector<node> ans;
string to_lower(string s){
for(int i=0;i<s.length();i++)
if(s[i]>='A'&&s[i]<='Z')
s[i]=s[i]-'A'+'a';
return s;
}
bool cmp(node a,node b){
if(a.tws!=b.tws)
return a.tws>b.tws;
else if(a.num!=b.num)
return a.num<b.num;
return a.name<b.name;
}
int main(){
int n,score;
string id,name;
scanf("%d",&n);
for(int i=0;i<n;i++){
cin>>id>>score>>name;
name=to_lower(name);
if(id[0]=='B')
school[name].scoreB+=score;
else if(id[0]=='A')
school[name].scoreA+=score;
else
school[name].scoreT+=score;
school[name].name=name;
school[name].num++;
}
for(map<string,node>::iterator it=school.begin();it!=school.end();it++){
it->second.tws=it->second.scoreB/1.5+it->second.scoreA+it->second.scoreT*1.5;
ans.push_back(it->second);
}
sort(ans.begin(),ans.end(),cmp);
printf("%d\n",ans.size());
for(int i=0;i<ans.size();i++){
if(i!=0&&ans[i].tws==ans[i-1].tws) ans[i].rrank=ans[i-1].rrank;
else ans[i].rrank=i+1;
}
for(int i=0;i<ans.size();i++)
cout<<ans[i].rrank<<" "<<ans[i].name<<" "<<ans[i].tws<<" "<<ans[i].num<<endl;
return 0;
}