(* O(n log n) *)
Scanf.scanf " %d" @@ fun n ->
  let sps = Array.init n @@ fun i -> Scanf.scanf " %s %d" @@ fun s p -> i + 1, s, p in
  Array.sort (fun (i, s, p) (j, s1, p1) -> p1 - p) sps;
  Array.stable_sort (fun (i, s, p) (j, s1, p1) -> compare s s1) sps; 
  Array.iter (fun (i, s, p) -> Printf.printf "%d\n" i) sps