def createData
  data = Array.new
  while input = $stdin.gets
    break if input == "\n"
    v = input.chomp.split(",")
    data << v[0]
  end
  return data
end

dataCurrentMonth = createData
dataPreviousMonth = createData

result = Hash.new
dataCurrentMonth.each{ |id|
  next if dataPreviousMonth.index(id) == nil
  c = dataCurrentMonth.count(id) + dataPreviousMonth.count(id)
  result.store(id.to_i, c)
}

result.sort.each{ |k, v| printf("%d %d\n", k, v) }