tmonth = []
lmonth = []

while line = gets
break if line == "\n"
tmonth << line.split(",").map(&:to_i).first
end

while line = gets
lmonth << line.split(",").map(&:to_i).first
end

sum = (tmonth & lmonth).sort
sum.each do |i|
  puts "#{i} #{tmonth.count(i) + lmonth.count(i)}"
end
