arr1=Array.new(1000,0)
arr2=Array.new(1000,0)
while gets
    break if $_=="\n"
    a,=$_.chomp.split(",").map(&:to_i)
    arr1[a]+=1
end
while !STDIN.eof?
    a,=gets.chomp.split(",").map(&:to_i)
    arr2[a]+=1
end
arr1.each_with_index do|item1,num|
    arr2.each do|item2|
        if item1>0 && item2>0
            puts"#{num} #{item1+item2}"
            break
        end
    end
end