#include <iostream>
#include <string>
#include <cstdio>
#include <map>
using namespace std;
typedef pair<int,int> P;

int main(){
    map <int,P> data;
    map <int,P>::iterator itr;
    string s;
    int num,tmp;
    while(getline(cin,s) && s.size() > 0){
        sscanf(s.c_str(),"%d,%d",&num,&tmp);
        if(data.find(num) != data.end()) data[num].first++;
        else data.insert(map <int,P>::value_type(num,P(1,1)));
    }
    while(getline(cin,s) && s.size() > 0){
        sscanf(s.c_str(),"%d,%d",&num,&tmp);
        if(data.find(num) != data.end()){
            data[num].first++;
            data[num].second++;
        }
        else data.insert(map <int,P>::value_type(num,P(1,-10000)));
    }
    for(itr=data.begin();itr!=data.end();itr++){
        if(itr->second.first > 1 && itr->second.second > 1) cout << itr->first << " " << itr->second.first << endl;
    }
}