import Data.List
import Data.Char

main = interact $ unlines . map (unwords . map show) . trading . read' . lines
 where read' ss = let (ts_last, (_:ts_this)) = span (not.null) (map (takeWhile isDigit) ss) in [ts_last, ts_this]

trading [ts_last, ts_this] = sort $ map aggregate $ sort $ intersect (nub ts_last) (nub ts_this)
 where aggregate n = [read n, length $ filter (== n) (ts_last ++ ts_this)]