#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
typedef struct
{
string a;
string b;
string c;
string d;
}people;
people m[100];
bool compare(people x,people y)
{
if(x.b!=y.b)
{
return x.b<y.b;
}
else if(x.c!=y.c)
{
return x.c<y.c;
}
else if(x.d!=y.d)
{
return x.d<y.d;
}
else
return 0;
}
int main()
{
int n;
cin >> n;
cin.get();
cin.get();
for(int i=0;i<n;i++)
{
cin >> m[i].a >> m[i].b >> m[i].c >> m[i].d;
}
sort(m,m+n,compare);
for(int i=0;i<n;i++)
{
cout << m[i].a << endl;
}
}