$dataset1 = {}
$dataset2 = {}
def set_data(line,dataset)
	id, date = line.split(',').map(&:to_i)
	if dataset.has_key?(id)
		dataset[id] << date
	else
		dataset[id] = [date]
	end
end

def print_data(smaller_data, bigger_data)
	smaller_data.sort.each do |key, value| 
		if bigger_data.has_key?(key)
			size = bigger_data[key].size + smaller_data[key].size
			puts "#{key} #{size}"
		end
	end
end

while line = gets
	break if line.chomp.empty?
	set_data(line.chomp,$dataset1)
end

while line = gets
	set_data(line.chomp,$dataset2)
end
$dataset1.size < $dataset2.size ? print_data($dataset1,$dataset2) : print_data($dataset2,$dataset1)