#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s[12]={"一班","二班","三班","四班",
"五班","六班","七班","八班","九班","十班"};
struct AA{
string a;
string b;
string c;
int d;
int f;
void input(){
cin>>a>>b>>c>>d;
for(int i=0;i<10;i++)
if(c==s[i])f=i;
}
void output(){
cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
}
}a[105];
bool cmp(AA a,AA b){
if(a.f==b.f)return a.d<b.d;
return a.f<b.f;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
a[i].input();
sort(a+1,a+n+1,cmp);
a[0].f=a[1].f-1;
a[n+1].f=a[n].f;
for(int i=1;i<=n;i++){
if(a[i].f!=a[i-1].f)
a[i].output();
}
return 0;
}
#include<string>
#include<algorithm>
using namespace std;
string s[12]={"一班","二班","三班","四班",
"五班","六班","七班","八班","九班","十班"};
struct AA{
string a;
string b;
string c;
int d;
int f;
void input(){
cin>>a>>b>>c>>d;
for(int i=0;i<10;i++)
if(c==s[i])f=i;
}
void output(){
cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
}
}a[105];
bool cmp(AA a,AA b){
if(a.f==b.f)return a.d<b.d;
return a.f<b.f;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
a[i].input();
sort(a+1,a+n+1,cmp);
a[0].f=a[1].f-1;
a[n+1].f=a[n].f;
for(int i=1;i<=n;i++){
if(a[i].f!=a[i-1].f)
a[i].output();
}
return 0;
}