import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  n <- readLn :: IO Int
  s <- map words . lines <$> getContents
  let restaurants = restaurant s
  let index = map (`elemIndex` restaurants) (guide s)
  putStrLn $ unlines $ map (show . maybe 0 (+1)) index

guide = sortBy(comparing fst) . sortBy(flip compare) . restaurant
restaurant [] = []
restaurant ([city,score]:xs) = (city, (read::String->Int) score):restaurant xs
