{-# LANGUAGE Arrows #-} import Control.Applicative import Control.Monad import Control.Arrow import Data.List ((\\), group, intersect) getInts :: IO [Int] getInts = map read . words <$> getLine main = do n <- readLn xs <- replicateM n getLine let f :: [String] -> [Int] f = map head . group . map read . init xs' = map ((f &&& last) . words) $ xs g [] ys = ys g ((ns,"YES"):xs) ys = g xs (intersect ys ns) g ((ns,"NO"):xs) ys = g xs (ys \\ ns) in putStrLn $ unwords . map show $ g xs' [0..9]