#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

void adjust( string &str )
{
	for ( unsigned int i = 0; i < str.length(); i++ )
	{
		if ( str[i] == ',' )
		{
			str[i] = ' ';
		}
	}

	return;
}

int main()
{
	string buffer;
	map<int,int> count;
	set<int> last, current;

	while ( true )
	{
		getline( cin, buffer );

		if ( buffer.length() == 0 )
		{
			break;
		}

		int number, date;
		
		adjust( buffer );

		istringstream( buffer ) >> number >> date;

		count[ number ]++;
		last.insert( number );
	}

	while ( cin >> buffer )
	{
		int number, date;
		
		adjust( buffer );
		
		istringstream( buffer ) >> number >> date;

		count[ number ]++;
		current.insert( number );
	}

	for ( map<int,int>::iterator it = count.begin(); it != count.end(); it++ )
	{
		if ( last.find( (*it).first ) != last.end() && current.find( (*it).first ) != current.end() )
		{
			cout << (*it).first << ' ' << count[ (*it).first ] << endl;
		}
	}

	return 0;
}