let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let lst = Array.to_list (Array.init n (fun i -> Scanf.scanf "%s %d\n" (fun s p -> (i+1,s,p)))) in
  let sort_lst = List.fast_sort
      (fun (ia, sa, pa) (ib, sb, pb) -> if (sa < sb || (sa = sb && pa > pb)) then -1 else if (sa > sb || (sa = sb && pa < pb)) then 1 else 0) lst in
  let print_lst = List.map (fun (i, s, p) -> string_of_int i) sort_lst in
  List.iter print_endline print_lst