#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
ll mem[1000000]={0};
ll mem2[1000000]={0};
int main(){
	string str="";
	bool f = false;
	int ma = 0;
	while(getline(cin,str)){
		int x;
		stringstream s(str);
		s >> x;
		if(str == "")f = true;
		else if(!f)mem[x]++;
		else if(f && mem[x] > 0){
			mem2[x]++;
			ma = max(ma,x);
		}
	}
	rep(i,ma+1){
		if(mem2[i] > 0)printf("%d %d\n",i,mem[i]+mem2[i]);
	}
	return 0;
}