lm,tm=[],[]
while gets
  break if $_.chomp==""
  lm<<$_.split(",").map(&:to_i)[0]
end
while gets
  tm<<$_.split(",").map(&:to_i)[0]
end
lm.sort.each do |n|
  puts "#{n} #{(lm+tm).count(n)}" if tm.include?(n)
end