

function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var R = new Array(N);
  for(var i=0;i<N;i++){
    var tmp=input[i+1].split(" ");
    R[i]=[i+1,tmp[0],parseInt(tmp[1])];
  }
  R.sort(function(a,b){
    if (a[1] < b[1]) return -1;
    if (a[1] > b[1]) return 1;
    if (a[2] < b[2]) return 1;
    if (a[2] > b[2]) return -1;
    return 0;
  })

  var ans="";
  for(var i=0;i<N;i++){
    if(i!=N-1){
      ans+=R[i][0]+"\n";
    }else{
      ans+=R[i][0];
    }
  }
  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));