#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<cstring>

using namespace std;

int main(){
	int a[1001]={0},b[1001]={0};
	int c,d;
	char tp[9];
	while(strcmp(fgets(tp,8,stdin),"\n")!=0){
		sscanf(tp,"%d,%d",&c,&d);
		a[c]++;
	}
	while(scanf("%d,%d",&c,&d)!=EOF){
		b[c]++;
	}
	for(int i=1;i<=1000;i++){
		if(a[i]>0&&b[i]>0)
		printf("%d %d\n",i,a[i]+b[i]);
	}
}
