import Control.Monad (replicateM)
import Data.List

main :: IO ()
main = do
  n <- (read :: String -> Int) <$> getLine
  sps <- zipWith (\k (a,b) -> (k,a,b)) ([1..] :: [Int]) . map ((\[a,b] -> (a,read b) :: (String, Int)) . words) <$> getNLine_ n
  mapM_ print . map (\(a,b,c) -> a) $ sortBy (\(_,b,c) (_,q,r) -> mappend (compare b q) (compare r c)) sps

getNLine_ :: Int -> IO [String]
getNLine_ n = replicateM n getLine