#include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<pair<string,int>> restraunt(n);
  map<pair<string,int>,int> rank;
  for(int i=0;i<n;i++){
    cin >> restraunt.at(i).first;
    cin >> restraunt.at(i).second;
    restraunt.at(i).second = 100 - restraunt.at(i).second;
    rank[restraunt.at(i)] = -1;
  }
  auto tmp(n) = restranut;
  sort(tmp.begin(),tmp.end());
  for(int i=0;i<n;i++){
    rank[tmp.at(i)] = i+1;
  }
  for(auto x : restraunt) cout << rank.at(x) << endl;
  
  return 0;
}
