import Data.List
import Control.Monad
main = do
  getLine
  sps <- map (\[s,p] -> (s, -1 * read p)) . map words . lines <$> getContents :: IO [(String, Int)]
  forM_ (sort $ zip sps [1..]) (\x -> print $ snd x)