#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

int main(){
    vector<int> last;
    char str[256];
    map<int,int> m;
    map<int,int>::iterator itm;
    char* tp;
    while(fgets(str,256,stdin)){
        if(strlen(str) == 1) break;
        tp = strtok(str,",");
        last.push_back(atoi(tp));
    }

    while(fgets(str,256,stdin)){
        if(str == "\0") break;
        tp = strtok(str,",");
        vector<int>::iterator it;
        for(it=last.begin();it!=last.end();++it){
            if(atoi(tp) == *it){
                if((itm = m.find(*it)) != m.end()){
                    itm -> second++;
                }else{
                    m.insert(pair<int,int>(*it,2));
                }
            }
        }
    }

    for(itm=m.begin(); itm != m.end(); ++itm){
        cout << itm->first << " " << itm->second << endl;
    }
    return 0;
}