#include<bits/stdc++.h>
using namespace std;
struct node
{
string name;
int y,m,d;
}c[101];
bool operator <(node a,node b)
{
if(a.y>b.y)return true;
if(a.y<b.y)return false;
if(a.y==b.y)
{
if(a.m>b.m)return true;
if(a.m<b.m)return false;
if(a.m==b.m)
{
if(a.d>b.d)return true;
else return false;
}
}
}
int main(){
int n,i;
scanf("%d",&n);
for(i=1;i<=n;i++) cin>>c[i].name>>c[i].y>>c[i].m>>c[i].d;
sort(c+1,c+n+1);
for(i=n;i>=1;i--) cout<<c[i].name<<endl;
return 0;
}
WA #5