#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
int main(void){
	char buff[256];
	int a,b;
	map<int,int> d[2];
	map<int,int> s;
	for(int i=0;i<2;i++){
		while(fgets(buff,sizeof(buff),stdin)&&buff[0]!='\n'){
			sscanf(buff,"%d,%d",&a,&b);
			d[i][a]++;
		}
	}
	for(map<int,int>::iterator itr=d[0].begin();itr!=d[0].end();itr++){
		if(itr->second&&d[1][itr->first]){
			s[itr->first]=itr->second+d[1][itr->first];
		}
	}
	for(map<int,int>::iterator itr=s.begin();itr!=s.end();itr++){
		cout<<itr->first<<" "<<itr->second<<endl;
	}
	return 0;
}