#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

	string str = "";
	map<int,int> last_month; last_month.clear();
	while (getline (cin, str ) ){
		if (str.empty() ) break;
		str = str.replace (str.find (','), 1, " " );
		stringstream ss (str );
		int id, day;
		ss >> id >> day;
		last_month[id]++;
	} // end loop

	map<int,int> curr_month; curr_month.clear();
	while (getline (cin, str ) ){
		str = str.replace (str.find (','), 1, " " );
		stringstream ss (str );
		int id, day;
		ss >> id >> day;
		curr_month[id]++;
	} // end while

	vector<P> res; res.clear();
	map<int,int>::iterator it = last_month.begin();
	for (; it != last_month.end(); it++ ){
		int id = (*it).first;
		int cnt = (*it).second;
		if (curr_month.count (id ) ){
			int cnt2 = curr_month[id];
			res.push_back (P (id, cnt+cnt2 ) );
		} // end if
	} // end for

	if (!res.empty() ) sort (ALL (res ) );
	rep (i, res.size() ){
		cout << res[i].first << ' ' << res[i].second << endl;
	} // end rep
		
	return 0;
}