#include <bits/stdc++.h> using namespace std; struct Mouse{ int weight; string color; }mouse[110]; bool cmp(Mouse m1,Mouse m2){ return m1.weight > m2.weight; } int main(){ int n; cin >> n; for(int i = 0;i < n;i ++)cin >> mouse[i].weight >> mouse[i].color; sort(mouse,mouse + n,cmp); for(int i= 0;i < n;i ++)cout << mouse[i].color << endl; return 0; }