local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local ior = io.input()
local n = ior:read("*n", "*n", "*l")
local mise = {}
for i = 1, n do
  local str = ior:read()
  local s, p = str:match("(%w+) (%d+)")
  p = tonumber(p)
  local tmp = {s, p, i}
  table.insert(mise, tmp)
end
for i = 1, n do
  -- print(unpack(mise[i]))
end
-- os.exit()
table.sort(mise, function(x, y)
  -- print("-")
  -- print(unpack(x))
  -- print(unpack(y))
  if(x[1] ~= y[1]) then
    return x[1] < y[1]
  else
    return x[2] > y[2]
  end
  -- if x[1] < y[1] then
  --   return true
  -- elseif y[1] < x[1] then
  --   return true
  -- else
  --   return x[2] < y[2]
  -- end
end)

for i = 1, n do
  print(mise[i][3])
end
