import Control.Applicative
import qualified Data.IntMap.Strict as I
import Data.IntMap.Strict (member, IntMap, adjust)
import Data.List

readTrades :: IntMap Int -> IO (IntMap Int)
readTrades m = do
    l <- getLine
    case l of
        "" -> return m
        ss -> readTrades (I.insertWith (+) custNum 1 m)
            where
                custNum = read . takeWhile (/= ',') $ ss

readBestCustomers :: I.IntMap Int -> IO (I.IntMap Int)
readBestCustomers bcs = do
    trades <- map (read . takeWhile (/= ',')) . lines <$> getContents
    return $ foldl' (\ m trade -> if trade `member` m
                                        then adjust succ trade m
                                        else m) bcs trades

main = do
    bcs <- readTrades I.empty
    readBestCustomers bcs >>=
        mapM_ (\(i,t) -> putStrLn . unwords . map show $ [i,t])
            . filter ((> 1) . snd) . I.toAscList