pm = {}

while (s = gets) != "\n"
  (n, c) = s.chomp.split(/,/).map(&:to_i)
  pm[n] = [] if !pm.key?(n)
  pm[n].push(c)
end

tm = {}

while s = gets
  (n, c) = s.chomp.split(/,/).map(&:to_i)
  tm[n] = [] if !tm.key?(n)
  tm[n].push(c)
end

pm.keys.sort.each do |k|
  if tm.key?(k)
    puts "#{k} #{pm[k].size + tm[k].size}"
  end
end