80分链接
#include<bits/stdc++.h>
using namespace std;
struct t{
int y,m,d,lj;
string student_name;
}a[105];
bool cmp(t a,t b){
if(a.y!=b.y){
return a.y<b.y;
}
else{
if(a.m!=b.m){
return a.m<b.m;
}
else if(a.d==b.d and a.m==b.m){
return a.lj>b.lj;
}
else{
return a.d<b.d;
}
}
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].student_name>>a[i].y>>a[i].m>>a[i].d;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
cout<<a[i].student_name<<endl;
}
return 0;
}