#include<cstdio>
#include<iostream>
#include<string>
#include <functional>
#include<queue>

using namespace std;

int main(void){

	priority_queue<int,vector<int>,greater<int> > data,data2;
	int sum,cnt=0;
	int min=-1,max=-1;
	int sta,w;
	string inp,num("");
	bool f=true;

	while(1){
		inp=getchar();
		if(inp=="\n"){
			f=true;
			inp=getchar();
			if(inp=="\n") break;
		}
		if(inp==","){
			sta=num.length()-1;
			w=1;
			sum=0;
			for(int j=sta;j>=0;j--){
				sum+=w*(num[j]-'0');
				w*=10;
			}
			data.push(sum);
			if(min==-1) min=sum,max=sum;
			else{
				if(min>sum) min=sum;
				if(max<sum) max=sum;
			}
			num=("");
			f=false;
		}
		if(f){
			num+=inp;
		}
	}

	while(cin>>inp){
		num=("");
		for(int j=0;;j++){
			if(inp[j]==','){
				break;
			}
			num+=inp[j];
		}
		sta=num.length()-1;
		w=1;
		sum=0;
		for(int j=sta;j>=0;j--){
			sum+=w*(num[j]-'0');
			w*=10;
		}
		data2.push(sum);
	}

	while(!data.empty()&&!data2.empty()){
		if(data.top()==data2.top()){
			sum=data.top();
			cnt=0;
			while(!data.empty()){
				if(data.top()!=sum) break;
				cnt++;
				data.pop();
			}
			while(!data2.empty()){
				if(data2.top()!=sum) break;
				cnt++;
				data2.pop();
			}
			cout<<sum<<" "<<cnt<<endl;
		}
		else if(data.top()<data2.top()) data.pop();
		else data2.pop();
	}

	return 0;
}