#include <bits/stdc++.h>
int main(void) {
  int N;
  int ai;
  int pi;
  typedef struct restaurant {
    char name[10];
    int point;
    int bango;
    int kasira;
    int kasira2;
    int kasira3;
    int ans;
  } rest;
  rest R[100];
  rest dummy;
  scanf("%d", &N);
  for (ai = 0; ai < N; ai++) {
    scanf("%s", R[ai].name);
    scanf("%d", &R[ai].point);
    R[ai].kasira = R[ai].name[0] - '0';
    R[ai].kasira2 = R[ai].name[1] - '0';
    R[ai].kasira3 = R[ai].name[2] - '0';
    R[ai].bango = ai + 1;
  }
  for (ai = 0; ai < N; ai++) {
    for (pi = ai + 1; pi < N; pi++) {
      if (R[ai].kasira > R[pi].kasira) {
        dummy = R[ai];
        R[ai] = R[pi];
        R[pi] = dummy;
      }
    }
  }
  for (ai = 0; ai < N; ai++) {
    for (pi = ai + 1; pi < N; pi++) {
      if (R[ai].kasira == R[pi].kasira) {
        if (R[ai].kasira2 == R[pi].kasira2) {
          if (R[ai].kasira3 > R[pi].kasira3) {
            dummy = R[ai];
            R[ai] = R[pi];
            R[pi] = dummy;
          } else if (R[ai].point < R[pi].point) {
            dummy = R[ai];
            R[ai] = R[pi];
            R[pi] = dummy;
          }
        } else if (R[ai].point < R[pi].point) {
          dummy = R[ai];
          R[ai] = R[pi];
          R[pi] = dummy;
        }
      }
    }
  }
  for (ai = 0; ai < N; ai++) {
    printf("%d\n", R[ai].bango);
  }
  return 0;
}
