n = io.read("*n", "*l")
t = {}
for i = 1, n do
  s = io.read()
  name, p = s:match("(%w+) (%d+)")
  t[i] = {name, tonumber(p), i}
end
table.sort(t, function(a, b)
  if a[1] ~= b[1] then
    return a[1] < b[1]
  else
    return a[2] > b[2]
  end
end)
for i = 1, n do
  print(t[i][3])
end
