import Control.Monad import Control.Applicative import Data.List main = do t <- readLn x <- map words <$> replicateM t getLine putStrLn . show $ solve [0..9] (map toTuple x) get1st (a,_,_,_,_) = a solve :: [Int] -> [(Int,Int,Int,Int,String)] -> Int solve (x:[]) _ = x solve ns ((a,b,c,d,r):xs) | r == "NO" = solve (ns \\ [a,b,c,d]) xs | r == "YES" = solve (intersect ns [a,b,c,d]) xs toTuple :: [String] -> (Int,Int,Int,Int,String) toTuple (a:b:c:d:e:[]) = (read a,read b,read c,read d,e)