#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  string S[N];
  int P[N];
  pair<string, int> res[N];
  for (int i = 0; i < N; i++) cin >> S[i] >> P[i];
  for (int i = 0; i < N; i++) res[i].first = S[i], res[i].second = P[i];
  sort(res, res + N);
  for (int i = 0; i < N;) {
    int count = 0;
    int pi[120] = {0};
    pi[0] = res[i].second;
    for (int k = i; k < N - 1; k++) {
      if (res[k].first == res[k + 1].first) {
        pi[count] = res[k].second;
        count++;
      } else {
        pi[count] = res[k].second;
        count++;
        break;
      }
    }
    sort(pi, pi + (count + 1), greater<int>());
    for (int k = 0; k < count; k++) cout << pi[k] << endl;
    for (int k = 0; k < i + count; k++) res[i + k].second = pi[k];
    i += count;
  }
  for (int i = 0; i < N; i++)
    cout << res[i].first << " " << res[i].second << endl;
  for (int i = 0; i < N; i++) {
    for (int k = 0; k < N; k++) {
      if (res[i].first == S[k] && res[i].second == P[k]) {
        cout << k + 1 << endl;
        break;
      }
    }
  }
  return 0;
}
