#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>	// istringstream
using namespace std;

int main(){
	string in;
	int bangou, day;
	// kongetu = (bangou, kaisuu);
	// sengetu = (bangou, day);
	map<int, int> kongetu, sengetu;

	while (getline(cin, in)){
		if (in.empty())	break;

		istringstream stream(in);
		stream >> bangou >> day;
		// kongetu.insert(pair<int, int>(bangou, day));
		kongetu[bangou]++;
	}
	
	while (scanf("%d,%d", &bangou, &day) != EOF){
		if (kongetu.count(bangou) > 0){
			kongetu[bangou]++;
			// 今月にもbangouがあるときのみinsertする.
			sengetu.insert(pair<int, int>(bangou, day));
		}
	}

	map<int, int>::iterator it = sengetu.begin();
	while (it != sengetu.end()){
		// sengetuとkongetuの両方にあるbangouの値(kaisuu)を出力する.
		cout << (*it).first << " " << kongetu[(*it).first] << endl;
		it++;
	}

	return 0;
}