#include <iostream> #include <string> #include <map> #include <algorithm> using namespace std; int main() { int weight,n; string color; map<int,string,greater<int>>mouse; cin>>n; while(n>0) { cin>>weight>>color; mouse.insert(std::pair<int,string>(weight,color)); n--; } for(map<int,string>::iterator iter =mouse.begin();iter!=mouse.end();iter++) { cout<<iter->second<<endl; } return 0; }