#include <bits/stdc++.h>
using namespace std;
struct res {
  string s1;
  int p;
  int cnt;
} r[1000];
bool cmp(const res a, const res b) {
  int len1 = a.s1.length();
  int len2 = b.s1.length();
  if (len1 == len2) {
    return a.p > b.p;
  }
  int len = max(len1, len2);
  if (len1 > len2) {
    for (int i = 0; i < len2; i++) {
      if (a.s1[i] == b.s1[i])
        ;
      else {
        return a.s1[i] < b.s1[i];
      }
    }
    return true;
  } else {
    for (int i = 0; i < len1; i++) {
      if (a.s1[i] == b.s1[i])
        ;
      else {
        return a.s1[i] < b.s1[i];
      }
    }
    return false;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i].s1 >> r[i].p;
    r[i].cnt = i + 1;
  }
  sort(r, r + n, cmp);
  for (int i = 0; i < n; i++) {
    cout << r[i].cnt << endl;
  }
}
