/*
#include <stdio.h>
#include <string.h>
struct student
{
char name[101];
int grade, rank;
};
int main()
{
struct student s[101];
int a, b, c[101], i, j;
int k = -1;
int loc = 0;
scanf("%d %d", &a, &b);
for (i=0; i<a; i++)
{
scanf("%s %d", s[i].name, &s[i].grade);
}
for (i=0; i<b; i++)
{
k = -1;#include <stdio.h>
#include <string.h>
struct student
{
char name[101];
int grade, rank;
};
int main()
{
struct student s[101];
int a, b, c[101], i, j;
int k = -1;
int loc = 0;
scanf("%d %d", &a, &b);
for (i=0; i<a; i++)
{
scanf("%s %d", s[i].name, &s[i].grade);
}
for (i=0; i<b; i++)
{
k = -1;
for(j=0; j<a; j++)
{
if(s[j].grade > k)
{
k = s[j].grade;
loc = j;
}
}
printf("%s\n", s[loc].name);
s[loc].grade = 0;
}
return 0;
}
//
/*
#include <stdio.h>
#include <string.h>#include <stdio.h>
#include <string.h>
struct student
{
char name[101];
int grade, rank;
};
int main()
{
struct student s[101];
int a, b, c[101], i, j;
int k = -1;
int loc = 0;
scanf("%d %d", &a, &b);
for (i=0; i<a; i++)
{
scanf("%s %d", s[i].name, &s[i].grade);
}
for (i=0; i<b; i++)
{
k = -1;
for(j=0; j<a; j++)
{
if(s[j].grade > k)
{
k = s[j].grade;
loc = j;
}
}
printf("%s\n", s[loc].name);
s[loc].grade = 0;
}
return 0;
}
struct list
{
int score;
int rank;
};
int main()
{
struct list s[201];
int a, i, j;
scanf("%d", &a);
for (i=0;i<a;i++)
{
scanf("%d" ,&s[i].score);
s[i].rank=1;
}
for (i=0;i<a;i++)
{
for (j=0;j<a;j++)
{
if (s[i].score<s[j].score)
{
++s[i].rank;
}
}
}
for (i=0;i<a;i++)
{
printf("%d %d", s[i].score, s[i].rank);
printf("\n");
}
return 0;
}
*/
/*
#include <stdio.h>
#include <string.h>
struct student
{
char name[101];
int grade, grade2, grade3, rank, rank2;
};
int main()
{
int a, i, j, k, loc;
k=-1;
struct student s[101];
scanf("%d", &a);
for(i=0;i<a;i++)
{
scanf("%s %d %d %d", s[i].name, &s[i].grade, &s[i].grade2, &s[i].grade3);
}
for (i=0;i<a;i++)
{
if (s[i].grade>k)
{
k=s[i].grade;
loc=i;
}
}
printf("%s", s[loc].name);
for (i=0;i<a;i++)
{
for (j=0;j<a;j++)
{
if (s[i].grade2<s[j].grade2)
{
++s[i].rank;
}
}
}
for (i=0;i<a;i++)
{
for (j=0;j<a;j++)
{
if (s[i].grade3<s[j].grade3)
{
++s[i].rank2;
}
}
}
printf(" %d %d", s[loc].rank+1, s[loc].rank2+1);
return 0;
}
*/
#include <stdio.h>
#include <string.h>
struct schedule
{
char name[101];
int year, month, day;
};
int main()
{
struct schedule s[101];
int a, i, j, k, loc;
k=9999;
scanf("%d", &a);
for (i=0;i<a;i++)
{
scanf("%s %d %d %d", s[i].name, &s[i].year, &s[i].month, &s[i].day);
}
for (i=0;i<a;i++)
{
if (s[i].year<k)
{
k=s[i].year;
loc=i;
}
else if (s[i].year==k)
{
if (s[i].month>s[loc].month)
{
printf("%s", s[loc].name);
}
else if (s[i].month==s[loc].month)
{
if (s[i].day>s[loc].day)
{
printf("%s", s[loc].name);
}
else if (s[i].day==s[loc].day)
{
printf("%s %s", s[i].name, s[loc].name);
}
else
{
printf("%s", s[i].name);
}
}
else
{
printf("%s", s[i].name);
}
}
}