import Data.Maybe
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as C

readInt' = fst.fromJust.C.readInt
readLnInt = map readInt'.C.words<$>C.getLine
readCsInt n = concat<$>replicateM n readLnInt

x ? (a,b) = if x then a else b

-- 死ぬほど型が違うって怒られるんだけどおれ何も悪いことしてるつもりない
-- どうして
main = do
 [n] <- readLnInt
 inputs <- C.words<$>C.getContents
 putStr.unlines.map show$ solve inputs

solve :: [C.ByteString] -> [Int]
solve s = ans $ cities (ording (1::Int) (pointing (tuplize s)))

ans :: [(C.ByteString,Int)] -> [Int]
ans ((city,point):s) = [point]++(null s)?([],ans s)

cities :: [(C.ByteString,Int)] -> [(C.ByteString,Int)]
cities = sortBy (\xs ys -> compare (fst xs) (snd ys))

tuplize :: [C.ByteString] -> [(C.ByteString,C.ByteString)]
tuplize (city:point:x) = [(city,point)]++(null x)?([],tuplize x)

ording :: Int -> [(C.ByteString,C.ByteString)] -> [(C.ByteString,Int)]
ording n ((city,point):s) = [(city,n)]++ (null s)?([],ording (n+1) s)

pointing :: [(C.ByteString,C.ByteString)] -> [(C.ByteString,C.ByteString)]
pointing s = reverse (sortBy (\xs ys -> compare (snd xs) (snd ys)) s)
