#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;
int main(){
    string str;
    map<int,int>t1,t2;
    while(getline(cin,str),str!=""){
        int n,m;
        sscanf(str.c_str(),"%d,%d",&n,&m);
        t1[n]++;
    }
    while(getline(cin,str),str!=""){
        int n,m;
        sscanf(str.c_str(),"%d,%d",&n,&m);
        t2[n]++;
    }
    map<int,int>::iterator ite=t1.begin();
    for(;ite!=t1.end();ite++){
        if(t2.find(ite->first)!=t2.end()){
            cout<<(ite->first)<<" "<<ite->second+((t2.find(ite->first))->second)<<endl;
        }
    }
}