-- Try yukicoder -- author: Leonardone @ NEETSDKASU import qualified Data.Set as S main = interact $ unlines . solve . map words . tail . lines solve xs = ans [] where hm = S.fromList $ map (!! 0) xs ys = map (!! 1) xs (ans, _) = foldl f (id, hm) ys f (g, s) y = if S.member y s then (g, s) else (g.(y:), S.insert y s)