//0065

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

int main(void)
{
	map<int, int> m1, m2;
	string str;
	stringstream ss;
	int index, day;
	char dummy;
	while(getline(cin, str), str.size() > 1)
	{
		ss.str(str);
		ss >> index >> dummy >> day;
		m1[index]++;
		ss.clear();
	}
	while(getline(cin, str), cin)
	{
		ss.str(str);
		ss >> index >> dummy >> day;
		m2[index]++;
		ss.clear();
	}

	for(map<int,int>::iterator ite = m1.begin();
		ite != m1.end();
		++ite)
	{
		if(m2[ite->first])
			cout << ite->first << ' ' << ite->second + m2[ite->first] << endl;
	}
	return 0;
}