#include <iostream>
#include <fstream>

using namespace std;

typedef struct ST_trade {
public:
	int trade_num;
	bool isTraded1;
	bool isTraded2;
	ST_trade() { trade_num = 0; isTraded1 = false; isTraded2 = false; }
} trade;

int main()
{
	trade a[1001];
	int no, date;
	char dummy;
	
	string buf;
	
	while ( getline(cin, buf) ) { 
		if ( buf.empty() ) break;
		sscanf(buf.c_str(), "%d%c%d", &no, &dummy, &date);
		a[no].isTraded1 = true; a[no].trade_num++;
	}
	while ( getline(cin, buf) ) { 
		if ( buf.empty() ) break;
		sscanf(buf.c_str(), "%d%c%d", &no, &dummy, &date);
		a[no].isTraded2 = true; a[no].trade_num++;
	}
	
	for (int i=1; i<=1000; i++) {
		if ( a[i].isTraded1 && a[i].isTraded2 ) cout << i << " " << a[i].trade_num << endl;
	}
	
	return 0;
}