/*
#include <stdio.h>
#include <stdlib.h>
int map[100][100] = { 0 };
int i, j, win;
int p, q;
int flag;
void dfs(int x, int y, int count, int num, int d, int white, int black)
{
if (x < 0 || x>18 || y < 0 || y>18
|| map[x][y] != num)
return;
if (map[x][y] == 1)
{
white += 1;
}
else if (map[x][y] == 2)
{
black += 1;
}
printf(" count : %d white : %d black : %d \n", count, white, black);
if (count == 1)
{
dfs(x - 1, y, count + 1, num, 1, white, black); // 상
dfs(x + 1, y, count + 1, num, 2, white, black); // 하
dfs(x, y - 1, count + 1, num, 3, white, black); // 좌
dfs(x, y + 1, count + 1, num, 4, white, black); // 우
dfs(x - 1, y - 1, count + 1, num, 5, white, black);
dfs(x - 1, y + 1, count + 1, num, 6, white, black);
dfs(x + 1, y - 1, count + 1, num, 7, white, black);
dfs(x + 1, y + 1, count + 1, num, 8, white, black);
}
else if (count >= 2)
{
if (d == 1)
dfs(x - 1, y, count + 1, num, 1, white, black); // 상
if (d == 2)
dfs(x + 1, y, count + 1, num, 2, white, black); // 하
if (d == 3)
dfs(x, y - 1, count + 1, num, 3, white, black); // 좌
if (d == 4)
dfs(x, y + 1, count + 1, num, 4, white, black); // 우
if (d == 5)
dfs(x - 1, y - 1, count + 1, num, 5, white, black);
if (d == 6)
dfs(x - 1, y + 1, count + 1, num, 6, white, black);
if (d == 7)
dfs(x + 1, y - 1, count + 1, num, 7, white, black);
if (d == 8)
dfs(x + 1, y + 1, count + 1, num, 8, white, black);
}
for(i=2; i<=count; i++)
{
if(i==5)
{
if (i == white || i == black)
{
p=x;
q=y;
if (i == white)
win = 1;
else
win = 2;
printf(" win : %d count : %d white : %d black : %d x : %d y : %d\n", win, count, white, black,p+1,q+1);
flag = 1;
}
}
else if(i>5)
{
printf(" win : %d count : %d white : %d black : %d x : %d y : %d\n", win, count, white, black,p+1,q+1);
printf("0");
break;
}
}
}
/*if (count >= 5)
{
if(count==5)
{
if (count == white || count == black) {
p=x; q=y;
if (count == white)
win = 1;
else
win = 2;
printf(" win : %d count : %d white : %d black : %d x : %d y : %d\n", win, count, white, black,p+1,q+1);
flag = 1;
}
}
else if(count>5)
{
printf(" win : %d count : %d white : %d black : %d x : %d y : %d\n", win, count, white, black,p+1,q+1);
flag=0;
}
}
*/
/*
int main()
{
for (i = 0; i < 19; i++)
{
for (j = 0; j < 19; j++)
{
scanf("%d", &map[i][j]);
}
}
for (i = 0; i < 19; i++)
{
for (j = 0; j < 19; j++)
{
flag = 0;
if (map[i][j] == 1 || map[i][j] == 2)
{
p=i;
q=j;
dfs(i, j, 1, map[i][j], 0, 0, 0);
if (flag==1)
{
printf("%d\n", win);
if(j>q)
printf("%d %d\n", p+1,q+1);
else if(j==q)
{
if(p<i)
printf("%d %d\n", p+1,q+1);
else
printf("%d %d\n",i+1,j+1);
}
else
printf("%d %d\n", i+1,j+1);
//printf("%d %d\n", p + 1, q + 1);
i = 18;
j = 18;
}
}
}
}
if (flag == 0)
printf("%d", flag);
}
*/
/*
#include <stdio.h>
#include <string.h>
typedef struct
{
char name[10];
int score;
}student;
int main()
{
int n,m;
student st[101], tmp;
int max=0,cnt=0;
scanf("%d %d", &n, &m);
for(int i=1;i<=n;i++)
{
scanf("%s %d", st[i].name, &st[i].score);
}
for(int i=1;i<n;i++)
{
for(int j=1;j<=n-i;j++)
{
if(st[j].score< st[j+1].score)
{
tmp=st[j];
st[j]=st[j+1];
st[j+1]=tmp;
}
}
}
for(int i=1;i<=m;i++)
printf("%s\n", st[i].name);
}
*/
/*
#include <stdio.h>
#include <string.h>
typedef struct
{
int num;
int math;
int inf;
}student;
int main()
{
int n,i;
student st[1001],tmp;
scanf("%d", &n);
for(i=1;i<=n;i++)
{
scanf("%d %d", &st[i].math, &st[i].inf);
st[i].num=i;
}
for(i=1;i<n;i++)
{
for(int j=1;j<=n-i;j++)
{
if(st[j].math<st[j+1].math)
{
tmp=st[j];
st[j]=st[j+1];
st[j+1]=tmp;
}
else if(st[j].math == st[j+1].math)
{
if(st[j].inf<st[j+1].inf)
{
tmp=st[j];
st[j]= st[j+1];
st[j+1]=tmp;
}
}
}
}
for(i=1;i<=n;i++)
printf("%d %d %d\n", st[i].num,st[i].math, st[i].inf);
return 0;
}
strcmp("abc","def")<0
strcmp("abc","abc")==0
*/
#include <stdio.h>
#include <string.h>
typedef struct
{
char name[10];
int year;
int month;
int day;
}noun;
int main()
{
int m,i,s1,s2;
noun n[101],tmp;
scanf("%d", &m);
for(i=1;i<=m;i++)
{
scanf(" %s %d %d %d", n[i].name, &n[i].year, &n[i].month, &n[i].day);
}
for(i=1;i<m;i++)
{
for(int j=1;j<=m-i;j++)
{
if(n[j].year>n[j+1].year)
{
tmp=n[j];
n[j]=n[j+1];
n[j+1]=tmp;
}
else if(n[j].year == n[j+1].year)
{
if(n[j].month>n[j+1].month)
{
tmp=n[j];
n[j]=n[j+1];
n[j+1]=tmp;
}
else if(n[j].month == n[j+1].month)
{
if(n[j].day>n[j+1].day)
{
tmp=n[j];
n[j]=n[j+1];
n[j+1]=tmp;
}
else if(n[j].day == n[j+1].day)
{
if(strcmp(n[j].name,n[j+1].name)>0)
{
tmp=n[j];
n[j]=n[j+1];
n[j+1]=tmp;
}
}
}
}
}
}
for(i=1;i<=m;i++)
printf("%s\n", n[i].name);
return 0;
}