import Control.Monad
import Data.List
import Data.Function (on)

main = do
  li <- getLine
  let n = read li
  sps <- forM [1..n] (\_ -> do
    li <- getLine
    let [s,p] = words li
    let ip = read p
    return (s,ip)
    )
  let answer = compute sps
  mapM_ print answer

compute :: [(String,Int)] -> [Int]
compute sps = map snd $ concat $ map reverse $
              groupBy ((==) `on` (fst.fst)) $ sort $ zip sps [1..]
