n = gets.chomp
thismonth = []
lastmonth = []
until n.empty?
 x = n.split(",")
 a = x[0].to_i
 lastmonth << a
 n = gets.chomp
end

n = gets
until n.nil?
 x = n.split(",")
 a = x[0].to_i
 thismonth << a
 n = gets
end

customer = []
lastmonth.each do |k|
 if thismonth.include?(k)
   if customer.include?(k)
   else
      customer << k
   end
 end
end


qq = lastmonth.push(thismonth)
allcus = qq.flatten

customer2 = customer.sort
if customer.length >= 1
 customer2.each do |t|
  count = allcus.count(t)
  puts "#{t} #{count}"
 end
end
