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

int main(){
    int num, day;
    set<int> s1, s2;
    map<int, int> m1, m2;
    while(scanf("%d,%d", &num, &day) != EOF){
        s1.insert(num);
        m1[num]++;
    }
    while(scanf("%d,%d", &num, &day) != EOF){
        s2.insert(num);
        m2[num]++;
    }
    for(set<int>::iterator it = s1.begin(); it != s1.end(); it++){
        if(s2.find(*it) != s2.end()){
            cout <<*it <<" " <<(m1[*it] + m2[*it]) <<endl;
        }
    }
    return 0;
}