@this_month = {}
@last_month = {}

target = @this_month

gets(nil).split("\n").each do |line|
  if line.chomp == ''
    target = @last_month
    next
  end
  company, count = line.split(',').map(&:to_i)
  target[company] = 0 unless target[company]
  target[company] += 1
end

ans = {}
@this_month.each do |company, count|
  if @last_month[company]
    ans[company] = @this_month[company] + @last_month[company]
  end
end

ans.sort.each do |company, count|
  puts "#{company} #{count}"
end