#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <map>
#include <sstream>


#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;

struct ss{
	int ct;
	bool zm,cm;
//	ss(int ct, bool zm,bool cm) : ct(ct),zm(zm),cm(cm) {}
};

int main(void){

string ws;
int bg,dy,cnt =0,tuki=0;

map <int,ss> mp;
map <int,ss>::iterator itr;

	while(!cin.eof()){
		getline(cin,ws);
			if(ws == "") {
			tuki++;
			continue;
		}
		replace(ws.begin(),ws.end(),',',' ');
		stringstream zz;
		zz << ws;
		zz >> bg >> dy;
		if(mp.end() != mp.find(bg)){
			mp[bg].ct++;
		}else{
			mp[bg].ct=1;
		}
		if(tuki==0) mp[bg].zm = true;
		else		mp[bg].cm = true;
	
	}
	for (itr = mp.begin(); itr != mp.end(); itr++){
		if(itr->second.zm && itr->second.cm)
			cout << itr->first << " " << itr->second.ct << endl;
	}
	return 0;
	
}