let rec split_by f = function
  | [] -> ([],[])
  | hd :: tl -> if f hd then 
                  let (rl, wl) = split_by f tl in (hd :: rl, wl)
                else ([], hd :: tl)
       
let rec group_by f = function
  | [] -> []
  | hd :: tl -> let (rl, wl) = split_by (f hd) tl in (hd :: rl) :: group_by f wl


let solve bl al = 
  let trl lst = List.map (fun x -> (fst (List.hd x), List.length x)) @@ group_by (fun (x1, y1) (x2, y2) -> x1 = x2) @@ List.sort (fun (x1, y1) (x2, y2) -> compare x1 x2) lst in
  let rec iter xs ys = 
    match (xs, ys) with
    | ((xi, xn)::xt, (yi, yn)::yt) -> if xi = yi then (xi, xn + yn) :: iter xt yt
                                      else if xi > yi then iter xs yt else iter xt ys
    | _ -> [] in
  let bl' = trl bl in
  let al' = trl al in
  let rst = iter bl' al' in
  List.iter (fun (x, y) -> Printf.printf "%d %d\n" x y) rst

let rec read1 () =
  let s = read_line () in
  if s = "" then []
  else let (x, y) = Scanf.sscanf s "%d,%d" (fun x y -> (x, y)) in
       (x, y) :: read1 ()

let rec read2 () =
  try
    let s = read_line () in
    let (x, y) = Scanf.sscanf s "%d,%d" (fun x y -> (x, y)) in
    (x, y) :: read2 ()
  with
    End_of_file -> []
                  
let _ = 
  let bl = read1 () in
  let al = read2 () in
  solve bl al