#include<iostream>
using namespace std;int main(){int a,b,t=0,c[2][1010]={0};string s;while(getline(cin,s)){if(s=="")t++;a=0,b=0;while(s[b]>45)a*=10,a+=s[b]-48,b++;c[t][a]++;}for(t=0;t<1010;t++){a=c[0][t],b=c[1][t];if(a&&b)cout<<t<<" "<<a+b<<endl;}return 0;}