#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> cust;

	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		while (str.find(',') != string::npos ){
			str = str.replace(str.find(','), 1, " ");
		} // end while
		int c, d;
		stringstream ss(str);
		ss >> c >> d;
//		cout << "c: " << c << " d: " << d << endl;
		cust.insert (c);
	} // end loop

	map<int, int> curr;

	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		while (str.find(',') != string::npos ){
			str = str.replace(str.find(','), 1, " ");
		} // end while
		int c, d;
		stringstream ss(str);
		ss >> c >> d;
		++curr[c];
	} // end loop
/*
	set<int>::iterator its = cust.begin();
	for (; its != cust.end(); ++its){
		cout << (*its) << endl;
	} // end for	
*/
	map<int, int>::iterator it = curr.begin();
	for (; it != curr.end(); ++it){
		if (cust.count ((*it).first) || (*it).second > 1){
			cout << (*it).first << ' '; 
			cout << ( (*it).second + cust.count((*it).first) ) << endl;
		} // end if
	} // end for
		
	return 0;
}