#include <bits/stdc++.h> using namespace std; struct node{ int weight; string color; friend bool operator<(node n1,node n2) { return n1.weight < n2.weight; } }; int main(){ int n; while(cin>>n){ priority_queue<node> q; while(n--){ node tmp; cin>>tmp.weight>>tmp.color; q.push(tmp); } while (q.size()>0) { cout<<q.top().color<<endl; q.pop(); } } return 0; }