let () =
  let f x y = (x*60+y,x,y) and
      scanf = Scanf.scanf " %d %d" and
      comp (x1,_,_) (x2,_,_) = if x1 = x2 then 0 else if x1 < x2 then 1 else -1
  in
  let n1 = Scanf.scanf "%d" (fun x -> x) in
  let bus1 = Array.init n1 (fun x -> scanf f) in
  let n2 = Scanf.scanf " %d" (fun x -> x) in
  let bus2 = Array.init n2 (fun x -> scanf f) in
  let len1 = Array.length bus1 and
      len2 = Array.length bus2 in
  let rec merge h i j =
    if len1 > i || len2 > j then
      if len1 <= i then merge (bus2.(j)::h) i (j+1)
      else if len2 <= j then merge (bus1.(i)::h) (i+1) j
      else
        let (x1,_,_) = bus1.(i) and
            (x2,_,_) = bus2.(j) in
        if x1 > x2 then merge (bus1.(i)::h) (i+1) j
        else merge (bus2.(j)::h) i (j+1)
    else
      h
  in
  Array.sort comp bus1;
  Array.sort comp bus2;
  let list = merge [] 0 0 in
  let rec print prev = function
      [] -> ()
    | h::t ->
       let (h1,h2,h3) = h in
       if prev <> h1 then
           if prev = (-1) then
             Printf.printf "%d:%02d" h2 h3
           else
             Printf.printf " %d:%02d" h2 h3
       ;print h1 t
  in
  print (-1) list;print_newline ()
;;