#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<functional>
#include<string>
using namespace std;

int main(){
	int latte[2][1001]={},n=0;
	char str[100];
	for(int i=0;i<2;i++){
		while(fgets(str,100,stdin)){
			if(str[0]==10) break;
			latte[i][atoi(str)]++;
			n = max(n,atoi(str));
		}
	}
	for(int i=0;i<=n;i++){
		if(latte[0][i]>0 && latte[1][i]>0) printf("%d %d\n",i,latte[0][i]+latte[1][i]);
	}
    return 0;
}