/*
#include <stdio.h>
#include <stdlib.h>
struct cal
{
int country;
int number;
int score;
};
int main()
{
int n, i, j,max=0,mi = 1, a[3];
struct cal mar[101];
scanf("%d", &n);
for(i=1; i<=n; i++)
{
scanf("%d %d %d", &mar[i].country, &mar[i].number, &mar[i].score);
}
for(j=1; j<=2; j++)
{
for(i=1; i<=n; i++)
{
if(max < mar[i].score)
{
max = mar[i].score;
mi = i;
}
}
a[j]=mar[mi].country;
printf("%d %d\n",mar[mi].country, mar[mi].number);
mar[mi].score = 0;
max = 0;
}
for(i=1; i<=n; i++)
{
if(max < mar[i].score)
{
if(a[1]==a[2])
{
if(a[1]!=mar[i].country)
{
max = mar[i].score;
mi = i;
}
}
else
{
max = mar[i].score;
mi = i;
}
}
}
printf("%d %d\n",mar[mi].country, mar[mi].number);
mar[mi].score = 0;
max = 0;
return 0;
}
*/
/*
#include <stdio.h>
#include <string.h>
struct mar
{
char word[101];
int number;
};
int main()
{
int n, m, i, j, a=0;
struct mar cal[100001], question[100001];
scanf("%d %d", &n, &m);
for(i=1; i<=n; i++)
{
scanf("%s %d",cal[i].word, &cal[i].number);
}
for(i=1; i<=m; i++)
{
scanf("%s", question[i].word);
}
for(i=1; i<=m; i++)
{
for(j=1; j<=n; j++)
{
if(strcmp(question[i].word, cal[j].word)==0)
{
a=a+cal[j].number;
}
}
printf("%d\n", a);
a=0;
}
return 0;
}
*/
#include <stdio.h>
#include <string.h>
struct r
{
char word[100];
int total;
};
int main()
{
int y, m, d, c, n, i, j;
struct r ho[101];
struct r b;
scanf("%d",&n);
for(i=1; i<=n; i++)
{
scanf("%s %d %d %d",ho[i].word, &y, &m, &d);
ho[i].total = y*10000+m*100+d;
}
for(j=1; j<=n; j++)
{
b=ho[1];
for(i=2; i<=n; i++)
{
if(b.total > ho[i].total)
{
b=ho[i];
c=i;
}
}
printf("%s\n", b.word);
}
return 0;
}