n = gets.chomp.to_i
sp = []
1.step(n, 1) do |i|
  k = gets.chomp.split
  sp.push({s: k[0].to_s, p: k[1].to_i, i: i})
end
sp = sp.group_by {|sps| sps[:s]}.sort_by {|k,_v_as_array| k}

sp.each do |k,v|
  v.sort_by {|vv| - 1 * vv[:p]}.each {|vvv| puts vvv[:i]}
end