
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import qualified Data.Array.IO as A
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


main :: IO ()
main = do
    n <- readLn
    sps <- replicateM n $ do
        [s,p] <- words <$> getLine
        return (s,read p) :: IO (String,Int)
    let procs = (sortOn (fst . snd) . sortBy (flip $ comparing (snd . snd)) . zip [1..]) sps 
    mapM_ (print . fst) procs
