#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<bits//stdc++.h>
#include<functional>
using namespace std;
int main() {
	map<int, int>a;
	int c,d;
	map<int, int>::iterator it,it2;
	while(scanf("%d,%d",&c,&d)){
		it=a.find(c);
		if(it==a.end()){
			a.insert(map<int,int>::value_type(c,1));
		}
		else a[c]++;
	}
	map<int, int>b;
	while(scanf("%d,%d",&c,&d)){
		it=b.find(c);
		if(it==b.end()){
			b.insert(map<int,int>::value_type(c,1));
		}
		else b[c]++;
	}
	it=a.begin();
	while(it!=a.end()){
		it2=b.find((*it).first);
		if(it2!=b.end()){
			cout<<(*it).first<<" "<<(*it).second+(*it2).second<<endl;
		}
		it++;
	}
}