N = gets.chomp.to_i
SP = Array.new
for i in 1..N
    sp = gets.chomp.split(" ")
    sp[1] = sp[1].to_i
    sp << i
    SP << sp
end
SP.sort!{|a, b| (a[0] <=> b[0]).nonzero? || b[1] <=> a[1]}
SP.each do |sp|
    puts sp[2]
end