#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

const int MAXN=100;
struct Mouse{
    int weight;
    string color;
};

Mouse arr[MAXN];

bool Compare(Mouse a,Mouse b){
    return a.weight>b.weight;
}

int main() {
    int n;
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++){
            cin>>arr[i].weight>>arr[i].color;
        }
        sort(arr,arr+n,Compare);
        for(int i=0;i<n;i++){
            cout<<arr[i].color<<endl;
        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")