#include <stdio.h>


int main() {
	int f[3000] = {}, n[3000] = {}, k, d, t = 0;
	char s[100];
	while(gets(s)){
		if(s[0] == NULL)
			t++;
		else{
			sscanf(s, "%d,%d", &k, &d);
			if(t == 0){
				f[k]++;
			}
			else{
				n[k]++;
			}
		}
	}
	int i = 0;
	for(i = 0; i < 3000; ++i){
		if(n[i] && f[i])
			printf("%d %d\n", i, n[i] + f[i]);
	}
	return 0;
}