9敏
#include<bits/stdc++.h>
#define l long long
using namespace std;
struct q{
string a;
l b,c,d;
};
bool pq(q r,q t)
{
if(r.b<t.b)
return 1;
else if(r.b>t.b)
return 0;
else
{
if(r.c<t.c)
return 1;
else if(r.c>t.c)
return 0;
else
{
if(r.d<t.d)
return 1;
else if(r.d>t.d)
return 0;
else
return 0;
}
}
}
int main()
{
l n;
cin>>n;
q x[n+1];
for(int i=1;i<=n;i++)
cin>>x[i].a>>x[i].b>>x[i].c>>x[i].d;
sort(x+1,x+1+n,pq);
for(int i=1;i<=n;i++)
cout<<x[i].a<<endl;
return false;
}