#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
int main(){
	int id,d;
	map<int,int> lastm,currm;
	char buf[99];
	while(gets(buf)&&strlen(buf)){
		sscanf(buf,"%d,%d",&id,&d);
		lastm[id]++;
	}
	while(gets(buf)&&strlen(buf)){
		sscanf(buf,"%d,%d",&id,&d);
		currm[id]++;
	}
	for(__typeof(lastm.begin()) i=lastm.begin(); i!=lastm.end(); i++){
		if(currm[i->first]>0)cout<<i->first<<" "<<(i->second+currm[i->first])<<endl;
	}
	return 0;
}