#include<iostream>
#include<vector>
#include<string>
#include<sstream>
int main()
{
	std::vector<int>this_month(1000, 0);
	for (std::string str; std::getline(std::cin, str) && str.length() > 0;)
	{
		std::string num;
		std::getline(std::stringstream(str), num, ',');
		this_month[std::stoi(num) - 1]++;
	}
	std::vector<int>last_month(1000, 0);
	for (std::string str; std::getline(std::cin, str);)
	{
		std::string num;
		std::getline(std::stringstream(str), num, ',');
		last_month[std::stoi(num) - 1]++;
	}
	for (int i = 0; i < 1000; i++)
	{
		if (this_month[i] * last_month[i] != 0)
		{
			std::cout << i + 1 << ' ' << this_month[i] + last_month[i] << std::endl;
		}
	}
	return 0;
}
