#include<iostream> #include<algorithm> using namespace std; const int N = 1e5 + 10; struct Rat { int m; string color; } rats[N]; bool cmp(Rat r1, Rat r2) { return r1.m > r2.m; } int main(void) { int n; while (cin >> n) { for (int i = 0; i < n; i++) { cin >> rats[i].m >> rats[i].color; } sort(rats, rats + n, cmp); for (int i = 0; i < n; i++) { cout << rats[i].color << endl; } } return 0; }