#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int n;
  cin>>n;
  vector<tuple<string,int,int>> v;
  for(int i=1;i<=n;i++){
    string s;
    int p;
    cin>>s>>p;
    v.emplace_back(s,-p,i);
  }
  sort(v.begin(),v.end());
  for(auto x:v) cout<<get<2>(x)<<endl;
}
