#include <bits/stdc++.h>
#define range(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) range(i,0,n)
using namespace std;

map<int,int> c,p;

int main(void){
	while(1){
		string s;
		getline(cin,s);
		if(s=="") break;
		int a,b;
		sscanf(s.c_str(),"%d,%d",&a,&b);
		c[a]++;
	}
	while(1){
		string s;
		getline(cin,s);
		if(cin.eof()) break;
		int a,b;
		sscanf(s.c_str(),"%d,%d",&a,&b);
		p[a]++;
	}
	for(auto &i:c){
		if(p.find(i.first)!=p.end())
			cout << i.first <<" " << p[i.first]+c[i.first] << endl;
	}
	return 0;
}