N = gets.chomp.to_i

a = []
b = Array.new(1, Array.new(3) )

str1 = gets.split
b[0] = 1, str1[0], str1[1].to_i

x = 2
y = 0
while x <= N
  str1 = gets.split
  a = x, str1[0], str1[1].to_i
  y = 0
  i = 0
  while y == 0 && i < x-1
    if a[1] > b[i][1] || (a[1] == b[i][1] && a[2] < b[i][2])
      i += 1
    else
      y = 1
    end
  end
  b.insert(i,a)
  x += 1
end

for x in 0...N
  puts b[x][0]
end