#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

map<int,int> a;
vector<int> b;

int n,m;
char z;
int main(){
	while(cin>>n>>z>>m){
		if(a.find(n)==a.end())a.insert(n,1);
		else a[n]++;
	}
	while(cin>>n>>z>>m){
		if(a.find(n)!=a.end())b.push_back(n);
	}
	sort(b.begin(),b.end());
	for(int i=0;i<b.size();i++)cout<<n<<" "<<a[n]<<endl;
	return 0;
}