#include<iostream> #include<cstdio> #include<string> #include<algorithm> using namespace std; struct Mouse{ int weight; string color; }; bool Descend(Mouse a,Mouse b){ return a.weight>b.weight; } int main(){ int n; Mouse array[100]; while(scanf("%d\n",&n)!=EOF){ for(int i=0;i<n;++i){ cin>>array[i].weight>>array[i].color; } sort(array,array+n,Descend); for(int i=0;i<n;++i){ cout<<array[i].color<<endl; } } return 0; }