# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

# input
inputs = []
lc = 0
hh = {}
while l = $stdin.gets do
  if lc == 0
  else
    tmp = l.chomp.split(" ").map(&:to_s)
    if hh[tmp[0]] == nil
      hh[tmp[0]] = [[tmp[1].to_i, lc]]
    else
      hh[tmp[0]] << [tmp[1].to_i, lc]
    end
    inputs << tmp[0]
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end


inputs = inputs.uniq.sort

# body
if $debugFlag
  p hh
  p inputs
end

inputs.each do |x_i|
  hh[x_i].sort_by!{|x| x[0]}.reverse!
  hh[x_i].each do |y_j|
    puts y_j[1]
  end
end
