#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;

int main(){
    string str;
    stringstream ss;
    int max_num=-1,num,day,month=0;
    vector< vector<int> > data(2);

    for(auto &v:data){
        v.resize(10000);
        fill(v.begin(),v.end(),0);
    }

    while(getline(cin,str) && !str.empty()){
        ss<<str;
        ss>>num;
        ss.str("");
        ss.clear();
        data[month][num]++;
        max_num=max(max_num,num);
    }

    month++;

    while(getline(cin,str)){
        ss<<str;
        ss>>num;
        ss.clear();
        ss.str("");
        data[month][num]++;
        max_num=max(max_num,num);
    }

    for(int i=1;i<=max_num;i++){
        if(data[0][i]>0 && data[1][i]>0){
            cout<<i<<" "<<data[0][i]+data[1][i]<<endl;
        }
    }

    return 0;
}