#include <bits/stdc++.h>
using namespace std;
typedef struct{
string name,post;
long long pt;
int lvl,pos;
}people;
bool postcmp(people a){
if(a.post == "BangZhu"){
return 7;
}
else if(a.post == "BangZhu"){
return 6;
}
else if(a.post == "HuFa"){
return 5;
}
else if(a.post == "ZhangLao"){
return 4;
}
else if(a.post == "TangZhu"){
return 3;
}
else if(a.post == "JingYing"){
return 2;
}
else{
return 1;
}
}
bool cmp(people a,people b){
if(a.pt == b.pt){
return a.pos < b.pos;
}
return a.pt > b.pt;
}
bool cmp2(people a,people b){
if(postcmp(a) == postcmp(b)){
if(a.lvl == b.lvl){
return a.pos < b.pos;
}
return a.lvl > b.lvl;
}
return postcmp(a) > postcmp(b);
}
int main(){
int n;
cin >> n;
people list[n];
for(int i=0;i<n;i++){
cin >> list[i].name >> list[i].post >> list[i].pt >> list[i].lvl;
list[i].pos = i+1;
}
sort(list+3,list+n,cmp);
for(int i=3;i<n;i++){
if(i < 5){
list[i].post = "HuFa";
}
else if(i < 9){
list[i].post = "ZhangLao";
}
else if(i < 16){
list[i].post = "TangZhu";
}
else if(i < 41){
list[i].post = "JingYing";
}
else{
list[i].post = "BangZhong";
}
}
sort(list+3,list+n,cmp2);
for(int i=0;i<n;i++){
cout << list[i].name << ' ' << list[i].post << ' ' << list[i].lvl << '\n';
}
return 0;
}