#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main() {
	int prev[1001] = {0};
	int next[1001] = {0};
	string in;
	int num,d;
	while(getline(cin,in),in.size() > 0) {
		sscanf(in.c_str(),"%d,%d",&num,&d);
		prev[num]++;
	}
	while(~scanf("%d,%d",&num,&d)) {
		if(prev[num] > 0)
			next[num]++;
	}
	for(int i = 0; i < 1001; i++) {
		if(next[i] > 0) printf("%d %d\n",i,prev[i]+next[i]);
	}

	return 0;
}