data1 = Array.new()
data2 = Array.new()
i = 0
flag = 0


#File.open("test/trading","r") do |input|
	#while tmp = input.gets do
	while tmp = gets do
		if(tmp == "\n")
			flag = 1
			i = 0
		end
		if(flag == 0)
 			data1[i] = tmp
 			i += 1
 		elsif(tmp != "\n")
 			data2[i] = tmp
 			i += 1
 		end
	end
#end

data1 = data1.map(&:chomp)
data2 = data2.map(&:chomp)

j = 0

user1 = Array.new()
trade1 = Array.new()
user2 = Array.new()
trade2 = Array.new()

for i in data1
	a,b = i.split(",")
	user1.push(a.to_i)
	trade1.push(b.to_i)
end

for i in data2
	a,b = i.split(",")
	user2.push(a.to_i)
	trade2.push(b.to_i)
end


result_user = (user1.uniq&&user2.uniq).sort
result_score = Array.new()

for i in result_user
	a = user1.count(i) + user2.count(i)
	result_score.push(a)
end

0.step(result_user.size - 1,1){|index|
	print(result_user[index]," " + result_score[index].to_s + "\n")
}