#include<bits/stdc++.h> using namespace std; struct Mouse{ int weight; string str; }; int main() { int n; while(cin>>n) { Mouse mouse[n]; for(int i = 0;i<n;i++) { cin>>mouse[i].weight>>mouse[i].str; } for(int i = 0;i<n-1;i++) { for(int j = 0;j<n-i-1;j++) { if(mouse[j].weight<mouse[j+1].weight) { Mouse temp = mouse[j]; mouse[j] = mouse[j+1]; mouse[j+1] = temp; } } } for(int k = 0;k<n;k++) { cout<<mouse[k].str<<endl; } } }