#include <cstdio>
#include <map>

using namespace std;

int main()
{
	map<int, int> customers;
	int cid;
	char cdata[1024];

	while (fgets(cdata, sizeof(cdata), stdin), *cdata != '\n'){
		sscanf(cdata, "%d,%*d", &cid);
		if (customers.count(cid)) customers[cid] += 2;
		else customers.insert(make_pair(cid, 2));
	}
	while (~scanf(" %d,%*d", &cid)){
		if (customers.count(cid)){
			if (customers[cid] % 2 == 0) customers[cid]++;
			customers[cid] += 2;
		}
	}
	for (map<int, int>::iterator it = customers.begin(); it != customers.end(); it++){
		if (it->second % 2 != 0){
			printf("%d %d\n", it->first, it->second / 2);
		}
	}

	return (0);
}