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

int toInteger(string a) {
    int ret = 0;
    int keta = 0;
    for(int r = (int)a.size() - 1; r >= 0; r--) {
        ret += (a[r] - '0') * pow(10, keta++);
    }
    return(ret);
}

int main(void) {
    string input;
    map<int, int> count, check;
    set<int> s;
    //先月
    while(getline(cin, input)) {
        if(input.empty()) break;
        int pos = (int)input.find(',');
        int a = toInteger(input.substr(0, pos));
        if(count.count(a) == 0) {
            count[a] = 1; check[a] = 1;
        } else count[a]++;
        s.insert(a);
    }
    //今月
    while(getline(cin, input)) {
        if(input.empty()) break;
        int pos = (int)input.find(',');
        int a = toInteger(input.substr(0, pos));
        if(count.count(a) == 0) {
            count[a]++;
        } else{ count[a]++; if(check.count(a) != 0) check[a]++;}
        s.insert(a);
    }
    set<int>::iterator ite;
    for(ite = s.begin(); ite != s.end(); ite++) {
        if(check[*ite] >= 2 && check[*ite] <= 1000) {
            cout << *ite << " " << count[*ite] << endl;
        }
    }

    return(0);
}