#include<iostream>
#include<map>
#include<cstdio>
using namespace std;
int main(){
	bool month = false;
	map<int, pair<int, int> > com;
	int n;
	char s[50];
	while(cin.getline(s,50)){
		if(s == 0){month = true;continue;}
		sscanf(s,"%d,%*d",&n);
		if(!month){com[n].first = 1;}
		else if(month && com[n].first){com[n].first = 2;}
		com[n].second ++;
	}
	for(__typeof(com.begin()) i=com.begin(); i<com.end(); i++){
		if(i->second.first == 2){cout <<i->first<<" "<<i->second.second<<endl;}
	}
	return 0;
}