#include <bits/stdc++.h>
using namespace std;
long long n, p;
string s;
vector<pair<string, int> > vec;
bool mysort(pair<string, int> a, pair<string, int> b) {
  bool ret = false;
  if (a.first == b.first) {
    ret = (a.second % 1000) > (b.second % 1000);
  } else {
    int id = 0;
    while (a.first[id] == b.first[id]) {
      id++;
      if (id >= a.first.length()) {
        ret = true;
        break;
      }
      if (id >= b.first.length()) {
        ret = false;
        break;
      }
    }
    ret = a.first[id] < b.first[id];
  }
}
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> s >> p;
    vec.push_back(pair<string, int>(s, p + (i + 1) * 1000));
  }
  sort((vec.begin()), (vec.end()), mysort);
  for (long long i = 0; i < n; i++) cout << vec[i].second / 1000 << endl;
  return 0;
}
