#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef struct mouse{
	int weight;
	char color[100];
}mouse;

bool com(mouse left,mouse right)
{
	if(left.weight>right.weight)
	return true;
	else
	return false;
}


int main()
{
	mouse m[1000];
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d %s",&m[i].weight,m[i].color);
	}
	sort(m,m+n,com);
	for(int i=0;i<n;i++)
	{
		printf("%s\n",m[i].color);
	}
	
	
	
	
	
}

easy