#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define int long long
signed main(){
        char buf[4000];
        int c=0;
        map<int,int> sl;
        vector<int> f;
        while ( fgets(buf, 4000, stdin) != NULL) {
                if(buf[0]=='\n'){
                        c++;
                        continue;
                }
                int a,b;
                sscanf(buf,"%lld,%lld",&a,&b);
                if(c==0){
                        if( sl.count(a) > 0) sl[a]++;
                        else sl[a]=1;
                }else{
                        if( sl.count(a) > 0){
                                sl[a]++;
                                if(count(f.begin(),f.end(),a)==0)f.push_back(a);
                        }
                }
        }
        sort(f.begin(),f.end());
        for(auto el : f){
                cout << el << " " << sl[el] << endl;
        }
        return 0;
}