#include<bits/stdc++.h>
using namespace std;
int main()
{
    int kawa=0,company[2][10001]={};
    char str[1000];
    while(fgets(str,1000,stdin)){
        if(strcmp(str,"\n")==0)kawa++;
        else company[kawa][atoi(strtok(str,","))]++;
    }
    for(int i=0;i<10001;i++)if(company[0][i]!=0&&company[1][i]!=0)cout<<i<<" "<<company[0][i]+company[1][i]<<endl;
}