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