import Control.Monad
import Data.List

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 sps = map snd $ concat $ map reverse $ groupBy (fst.fst) $ sort $ zip sps [1..]
