#include<stdio.h>
struct student{
char name[21];
int score;
};
int main()
{
struct student arr[11],t;
for(int j=1;j<=5;j++)
{
scanf("%s %d",arr[j].name,&arr[j].score);
}
for(int z=1;z<=4;z++)
{
for(int x=1;x<=5-z;x++)
{
if(arr[x].score<arr[x+1].score)
{
t=arr[x]; arr[x]=arr[x+1]; arr[x+1]=t;
}
}
}
for(int b=1;b<=5;b++)
printf("%s \n",arr[b].name);
return 0;
}