#include<iostream>
#include<map>
#include<string>
#include<cstdlib>

int n, d;
std::map<int, int> cnt[2];
std::string s;

int main()
{
	bool f = false;
	while( std::getline( std::cin, s ) )
	{
		if( s == "" )
		{
			f = true;
			continue;
		}

		std::string::size_type i = s.find( "," );
		n = atoi( s.substr( 0, i ).c_str() );
		
		++cnt[f][n];
	}

	for( std::map<int, int>::iterator it = cnt[0].begin(); it != cnt[0].end(); ++it )
	{
		std::map<int, int>::iterator it2 = cnt[1].find( it->first );
		
		if( it2 != cnt[1].end() )
			std::cout << it->first << " " << it->second + it2->second << std::endl;
	}

	return 0;
}