#include <stdio.h>
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
using namespace std;

int N;
int t;
string S;
vector<pair<pair<string,int>,int>> p[110];

int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> S;
    cin >> t;
    p[i] = make_pair(make_pair(S,-t),i);
  }
  
  sort(p.begin(),p.end());
  for(int i=0;i<N;i++){
    cout << p[i] << endl;
  }
}
  
