thismonth = Hash.new( 0 )
lastmonth = Hash.new( 0 )

while line = $stdin.gets
	if line.chomp.size == 0 
		break
	end
	data = line.chomp.split(/,/).map{ |n| n.to_i }

	if thismonth[data[ 0 ]] == 0
		thismonth[data[ 0 ]] = 1
	else
		thismonth[data[ 0 ]] += 1
	end
end

while line = $stdin.gets
	data = line.chomp.split(/,/).map{ |n| n.to_i }
	if lastmonth[data[ 0 ]] == 0
		lastmonth[data[ 0 ]] = 1
	else
		lastmonth[data[ 0 ]] += 1
	end
end

thismonth.sort{ |(k1,v1),(k2,v2) | k1 <=> k2 }.each{|key,value|
	if lastmonth.key?( key )
		printf( "%d %d\n", key, value + lastmonth[ key ] )
	end
}
