import Data.List
import Text.Printf

main = do
    ss <- getContents
    let l1 = map (\x->read ("("++x++")")::(Int,Int)) $ takeWhile (\l->l/="") $ lines ss
    let l2 = map (\x->read ("("++x++")")::(Int,Int)) $ drop ((length l1)+1) $ lines ss
    let l1' = map fst l1
    let l2' = map fst l2
    let l12' = l1' ++ l2'
    let comp = sort $ nub $ filter (\i->elem i l2') l1'
    let ans = map (\i->(i,(length $ filter (==i) l12'))) comp
    mapM_ (\x->printf "%d %d\n" (fst x) (snd x)) ans