#include<map>
#include<set>
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main()
{
    map<int,int> cnt[2];
    set<int> idset[2];
    char s[64];
    int month=0;
    while(cin.getline(s,64)){
        if(s[0]=='0'){
            month=1;
            continue;
        }
 
        int id;
        sscanf(s,"%d,%*d",&id);
        cnt[month][id]++;
        idset[month].insert(id);
    }
 
    vector<int> intersect;
    set_intersection(idset[0].begin(),idset[0].end(),
                     idset[1].begin(),idset[1].end(),
                     inserter(intersect,intersect.begin()));
 
    for(int i=0;i<intersect.size();i++){
        int id=intersect[i];
        cout<<id<<" "<<cnt[0][id]+cnt[1][id]<<endl;
    }
 
    return 0;
}