#include <iostream>
#include <map>
#include <set>
#include <string>
#include <stdlib.h>

using namespace std;

void solve()
{
	map<int, int> Map;
	set<int> Set1;
	set<int> Set2;
	int a, b;
	char c;
	string str;
	while(getline(cin, str))
	{
		if(str == "")
		{
			break;
		}
		string temp;
		for(int i = 0; i < str.size(); ++i)
		{
			if(str[i] == ',')
			{
				a = atoi(temp.c_str());
			}
			else
			{
				temp += str[i];
			}
		}
		b = atoi(temp.c_str());
		++Map[a];
		Set1.insert(a);
	}
	while(cin >> a >> c >> b)
	{
		++Map[a];
		Set2.insert(a);
	}
	map<int, int>::iterator it = Map.begin();
	while(it != Map.end())
	{
		if(Set1.find(it->first) != Set1.end() && Set2.find(it->first) != Set2.end())
		{
			cout << it->first << " " << it->second << endl;
		}
		++it;
	}
}

int main()
{
	solve();
	return(0);
}