import Control.Monad
import Data.List

solve :: [(String, Int)] -> [(String, Int)] -> [Int]
solve [] _ = []
solve ((name, inc):ss) t = case lookup name t of
  Just dec -> (inc - dec) : solve ss t
  Nothing  -> inc : solve ss t

main :: IO ()
main = do
  let convert = map (\x -> (head x, length x)) . group . sort
  n <- readLn
  ss <- convert <$> replicateM n getLine
  m <- readLn
  ts <- convert <$> replicateM m getLine
  print . max 0 $ maximum $ solve ss ts
