#include<iostream>
#include<cstdio>
#include<map>
#include<string>
using namespace std;
int main(){
	string s;
	bool month = false;
	map<int,pair<int,int> > com;
	for(;;){
		getline(cin,s);
		if(s == ""){
			if(!month){month = true;continue;}
			else{break;}
		}
		int a = 0;
		sscanf(s.c_str(),"%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;
}