#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen ("testcase.trading", "r", stdin);
	string str = "";

	set<int> prev;

	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		str = str.replace (str.find (','), 1, " ");
		int c, dummy;
		stringstream ss(str);
		ss >> c >> dummy;
		prev.insert (c );
	} // end loop

	map<int, int> curr;

	while (getline (cin, str ) ){
		if (str.empty() ){
			continue;
		} // end if
		str = str.replace(str.find(','), 1, " ");
		int c, dummy;
		stringstream ss(str);
		ss >> c >> dummy;
		++curr[c];
	} // end loop

	map<int, int>::iterator it = curr.begin();
	for (; it != curr.end(); ++it){
		int count = (*it).second;
		int num = (*it).first;

		if (prev.count(num) ){
			++count;
			cout << num << ' ' << count << endl;
		} // end if
	} // end for

	return 0;
}