#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

map<int,int> n1,n2;
char str[100];
int main(){
    for(;;){
        gets(str);
        if(strlen(str)==0) break;
        int a;
        sscanf(str,"%d,%*d",&a);
        n1[a]++;
    }
    while(scanf("%s\n",str)!=-1){
        int a;
        sscanf(str,"%d,%*d",&a);
        n2[a]++;
    }
    for(map<int,int>::iterator it=n1.begin();it!=n1.end();it++){
        if(n2[it->first]>0) printf("%d %d\n",it->first,it->second+n2[it->first]);
    }
}