kokyaku = Hash.new{|h,k| h[k] = Array.new(2){[]}}
month = 0
readlines.each{|line|
  if line =~ /^$/
    month += 1
    next
  end
  c,d = line.split(",").map(&:to_i)
  kokyaku[c][month] << d
}

kokyaku.sort.each{|h, k|
  if kokyaku[h][0].size > 0 &&  kokyaku[h][1].size > 0
    puts "#{h} #{kokyaku[h][0].size + kokyaku[h][1].size}"
  end
}