def main(input = STDIN)
  prev_hash = Hash.new{0}
  while (datum = input.gets) != "\n"
    datum = datum.split(",").map(&:to_i)
    prev_hash[datum[0]] += 1
  end
  this_hash = Hash.new{0}
  this = []
  while (datum = input.gets)
    datum = datum.split(",").map(&:to_i)
    this.push(datum[0])
    this_hash[datum[0]] += 1
  end
  this.sort!.uniq!
  this.each{|c|
    if (prev_hash[c] != 0 and this_hash[c] != 0)
      puts c.to_s + " " + (prev_hash[c] + this_hash[c]).to_s + "\n"
    end
  }
end
main