#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

typedef long long ll;

int t[10000][2],m=0;
string d;

int main(){
    while(getline(cin,d)){
	if(d.size()==0)m++;
	if(m==2)break;
	int cur=0,n=0;
	while(cur<d.size()){
	    if(isdigit(d[cur])){n=n*10+d[cur]-'0';cur++;}
	    else break;
	}
	t[n][m]++;
    }
    for(int i=0;i<10000;i++)if(t[i][0]&&t[i][1])cout<<i<<" "<<t[i][0]+t[i][1]<<endl;
}