#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <functional>
#include <climits>
#define quickio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl "\n"
using namespace std;
typedef long long ll;
struct Stu
{
string name;
int year;
int month;
int day;
};
bool cmp(Stu s1, Stu s2)
{
if (s1.year != s2.year)
return s1.year < s2.year;
if (s1.month != s2.month)
return s1.month < s2.month;
if (s1.day != s2.day)
return s1.day < s2.day;
return false;
}
void solve()
{
int n;
cin >> n;
vector<Stu>v(n);
for (int i = 0; i < n; i++)
{
cin >> v[i].name >> v[i].year >> v[i].month >> v[i].day;
}
sort(v.begin(), v.end(), cmp);
for (int i = 0; i < n; i++)
{
cout << v[i].name << endl;
}
}
int main()
{
solve();
return 0;
}