#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main( void )
{
	map <int,int> T;
	vector <int> P;
	vector <int> L;

	string in;
	while ( 1 )
	{
		in = "";
		getline( cin, in );
		if ( in == "" ) break;
		replace( in.begin(), in.end(), ',', ' ' );
		istringstream is( in );

		int no, d;
		is >> no >> d;
		T[no]++;

		if ( find( P.begin(), P.end(), no ) == P.end() )
		{
			P.push_back( no ) ;
		}
	}

	while ( cin >> in )
	{
		replace( in.begin(), in.end(), ',', ' ' );
		istringstream is( in );
		int no, d;
		is >> no >> d;
		T[no]++;

		if ( find( L.begin(), L.end(), no ) == L.end() && find( P.begin(), P.end(), no ) != P.end() )
		{
			L.push_back( no );
		}
	}

	sort( L.begin(), L.end() );

	for ( vector <int>::iterator it = L.begin(); it != L.end(); it++ )
	{
		cout << *it << " " << T[*it] << endl;
	}

	return 0;
}