#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main(){
long i,n[1001]={0},n2[1001]={0},nn;
string s;
stringstream ss;
while(getline(cin,s)){
if(s=="")break;
ss.str("");ss<<s;
ss>>nn;
n[nn]++;
}
while(getline(cin,s)){
if(s=="")break;
ss.str("");ss<<s;
ss>>nn;
n2[nn]++;
}
for(i=0;i<1000;i++)if(n[i]*n2[i]>0)cout<<i<<" "<<n[i]+n2[i]<<endl;
return 0;
}