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 = 0
  dataCurrentMonth.each{|n| c += 1 if id == n}
  dataPreviousMonth.each{|n| c+= 1 if id == n}
  result.store(id.to_i, c)
}

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