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

int main()
{
	int a, b;
	map<int, int> company;
	map<int, int>::iterator it;
	string s;
	char c;

	while ( getline(cin, s) ) {
		a = -1;
		stringstream ss;
		ss.str(s);
		ss>>a>>c>>b;
		if (a==-1) break;

		company[a]--;
	}

	while ( getline(cin, s) ) {
		a = -1;
		stringstream ss;
		ss.str(s);
		ss>>a>>c>>b;
		if (a==-1) break;

		if (company[a] < 0) company[a] *= -1;
		company[a] ++;
	}

	for (it = company.begin(); it != company.end(); it++)
		if ((*it).second > 0)
			cout<<(*it).first<<" "<<(*it).second<<endl;
	return 0;
}