let inp_loop_index : (int -> 'a) -> int -> 'a list = fun inp_fun n ->
  let rec loop i =
    if i = n then []
    else
      let x = inp_fun i in
      x :: loop (i + 1)
  in loop 0
    
let () =
  let n = int_of_string (input_line stdin) in
  let l = inp_loop_index (fun i -> Scanf.sscanf (input_line stdin) "%s %d" (fun s p -> (i + 1, s, p))) n in
  let l' = List.sort (fun (i1, s1, p1) (i2, s2, p2)->
               if s1 > s2 then 1
               else if s1 < s2 then -1
               else if p1 > p2 then -1
               else if p1 < p2 then 1
               else 0) l in
  List.iter
    (fun (i, s, p) ->
      print_int i;
      print_newline ()) l'
