#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<string, int>> restraunt(n), tmp(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;
    tmp.at(i) = restraunt.at(i);
    rank[restraunt.at(i)] = -1;
  }
  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;
}
