#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int num, day;
	vector<int> mon;
	map<int, int> res;
	while (scanf("%d%*c%d", &num, &day)!=EOF) {
		mon.push_back(num);
	}
	while (scanf("%d%*c%d", &num, &day)!=EOF) {
		int cnt = count(mon.begin(), mon.end(), num);
		if (cnt != 0) {
			if (res.find(num) == res.end()) {
				res.insert(make_pair(num, cnt+1));
			} else {
				res[num]++;
			}
		}
	}
	map<int, int>::iterator itr;
	for (itr = res.begin(); itr != res.end(); itr++) {
		printf("%d %d\n", (*itr).first, (*itr).second);
	}
}