#include<iostream>
#include<cstdio>
using namespace std;

int main(){

    string str;
    int company[1001] = {0};
    int number=0,n;
    bool rowFlag[1001];

    for(int i=0; i<1001; i++){
        rowFlag[i] = false;
    }

    while(getline(cin,str) , str != ""){
        for(int i=0; i<str.length(); i++){
            if(str[i] == ','){
                company[number]++;
                number = 0;
                break;
            }
            number *= 10;
            number += (int)str[i] - '0';
        }
    }

    while(scanf("%d,%d",&number,&n) != EOF){
        if(company[number] > 0){
            rowFlag[number] = true;
            company[number]++;
        }
    }

    for(int i=1; i<1001; i++){
        if(rowFlag[i]){
            cout<<i<<' '<<company[i]<<endl;
        }
    }

    return 0;
}