import Data.List
f::Int->[String]->[(String,Int,Int)]
f _ []=[]
f c (e:es)=let t=words e
           in (t!!0,(-1::Int)*(read (t!!1)::Int),c):f (c+1) es

main = do
       u<-getLine
       a<-getContents
       let t=sort $ f 1 (lines a)
       mapM_ putStrLn $ map (\(_,_,x)->show x) t