#include <iostream>
#include <vector>
#include <stdio.h>
#include <cstdio>
using namespace std;
int main(){
	int com,d;
	vector<int> cus;
	while(scanf("%d,%d",&com,&d)){
		cus.push_back(com);
	}
	scanf("\n");
	while(scanf("%d,%d",&com,&d)!=EOF){
		cus.push_back(com);
	}
	for(int i=1;i<=1000;i++){
		int count=0;
		for(int j=0;j<cus.size();j++){
			if(cus[j]==i) count++;
		}
		if(count>1) cout<<i<<" "<<count<<endl;
	}
	return 0;
}