#include <stdio.h>
#include <string.h>

typedef struct{
	int n;
	int day[1000];
	int d_n;
}data;

int main(void){
	data com[1001];
	int sec[1001];
	int index = 0;
	int sec_index = 0;
	char str[100];
	int num;
	int a;

	for(int i=0; i<1001; i++){
		com[i].d_n = 0;
	}

	while(1){
		fgets(str, 99, stdin);
		for(int i=0;; i++){
			if(str[i] == '\n'){
				str[i] = '\0';
				break;
			}
		}
		if(strlen(str) == 0) break;
		sscanf(str, "%d,%d", &num, &a);

		int i;
		for(i=0; i<index; i++){
			if(com[i].n == num){
				int j;
				for(j=0; j<(com[i].d_n); j++){
					if(com[j].day[j] == a) break;
				}
				if(j == com[i].d_n){
					com[i].day[com[i].d_n] = a;
					(com[i].d_n)++;
				}
				break;
			}
		}
		if(i == index){
			com[index].n = num;
			com[index].day[com[index].d_n] = a;
			(com[i].d_n)++;
			index++;
		}
	}

	while(scanf("%d,%d", &num, &a) != EOF){
		for(int i=0; i<index; i++){
			if(com[i].n == num){
				int j;
				for(j=0; j<sec_index; j++){
					if(sec[j] == num) break;
				}
				if(j == sec_index){
					sec[sec_index] = num;
					sec_index++;
				}
			}
		}
		int i;
		for(i=0; i<index; i++){
			if(com[i].n == num){
				int j;
				for(j=0; j<(com[i].d_n); j++){
					if(com[j].day[j] == a) break;
				}
				if(j == com[i].d_n){
					com[i].day[com[i].d_n] = a;
					(com[i].d_n)++;
				}
				break;
			}
		}
		if(i == index){
			com[index].n = num;
			com[index].day[com[index].d_n] = a;
			(com[i].d_n)++;
			index++;
		}
	}

	for(int i=sec_index-1; i>0; i--){
		for(int j=0; j<i; j++){
			if(sec[j] > sec[j+1]){
				int temp = sec[j];
				sec[j] = sec[j+1];
				sec[j+1] = temp;
			}
		}
	}

	for(int i=0; i<sec_index; i++){
		printf("%d ", sec[i]);
		int cnt = 0;
		for(int j=0; j<index; j++){
			if(com[j].n == sec[i]){
				printf("%d\n", com[j].d_n);
			}	
		}
	}

	return 0;
}