#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  string a[100];
  string p[100];
  string con[100];
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int tem;
    cin >> a[i] >> tem;
    p[i] = to_string(100 - tem);
    if (p[i].compare("100") == 0)
      con[i] = a[i] + "999" + to_string(i + 1);
    else
      con[i] = a[i] + p[i] + to_string(i + 1);
  }
  sort(con, con + N);
  for (int i = 0; i < N; ++i)
    cout << con[i].substr((int)(con[i].length() - 1), 1) << "\n";
  return 0;
}
