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

int main()
{
	string s;
	bool prev = true;
	map<int, int> lm, tm;
	while (getline(cin, s)) {
		string::size_type p = s.find_first_of(",");
		if (p == string::npos) {
			prev = false;
			continue;
		}

		int num = atoi(s.substr(0, p).c_str());
		if (prev)
			++lm[num];
		else
			++tm[num];
	}

	for (map<int, int>::iterator it = lm.begin(); it != lm.end(); ++it) {
		map<int, int>::iterator jt = tm.find(it->first);
		if (jt != tm.end())
			cout << it->first << " " << it->second+jt->second << endl;
	}
	return 0;
}