h1 = Hash.new(0)
loop {
    i, k = gets.split(",").map &:to_i
    break if !k
    h1[i] += 1
}
h2 = Hash.new(0)
loop {
    s = gets
    break if !s
    i, k = s.split(",").map &:to_i
    h2[i] += 1
}
(h1.keys & h2.keys).sort.each{|i|
    puts "#{i} #{h1[i] + h2[i]}"
}