#include <stdio.h>
#include <cmath>
#include <algorithm>

int main(){
	int past[1001],current[1001],tmp_code,tmp_date;
	char buf[30];

	for(int i=0; i < 1001; i++){
		past[i] = current[i] = 0;
	}

	while(true)
	{
		fgets(buf,30,stdin);
		if(buf[0] == '\n'){
			break;
		}
		tmp_code = 0;
		for(int i=0;buf[i] != ',';i++){
			tmp_code = 10*tmp_code + (buf[i] - '0');
		}
		past[tmp_code]++;
	}

	while(scanf("%d,%d",&tmp_code,&tmp_date)!=EOF){
		current[tmp_code]++;
	}

	for(int i = 0; i < 1001; i++){
		if(past[i] > 0 && current[i] > 0){
			printf("%d %d\n",i,past[i]+current[i]);
		}
	}

	return 0;
}

