import Control.Monad
import Data.List

solveSub [x] = [x]
solveSub (x:xs)
    | x0 > y0 = y:x:ys
    | x0 == y0 && x1 <= y1 = y:x:ys
    | x0 == y0 && x1 > y1 = x:y:ys
    | otherwise = x:y:ys
    where
        (y:ys) = solveSub xs
        x0 = (fst x)!!0
        y0 = (fst y)!!0
        x1 = read ((fst x)!!1) :: Int
        y1 = read ((fst y)!!1) :: Int

solve [] = []
solve xs = y : solve ys
    where
        (y:ys) = solveSub xs

main = do
    n <- readLn :: IO Int
    spn <- replicateM n (words <$> getLine)
    putStr $ unlines $ map (show.snd) $ solve $ zip spn [1..n]
