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

class data
{
public:
	int nm,ct;
	data(){nm=ct=0;}
};

int main()
{
	char c;
	int n,d,m=1;
	string  str;
	map<int,data> mp;
	map<int,data>::iterator it;

	while(getline(cin,str))
	{
		if(str=="")
		{
			m=2;
			continue;
		}

		stringstream ss;
		ss << str;
		ss >> n >> c >> d;

		mp[n].nm |= m;
		mp[n].ct++;
	}

	for(it=mp.begin(); it!=mp.end(); it++)
	{
		if(it->second.nm==3)
		{
			cout << it->first << " " << it->second.ct << endl;
		}
	}
}