#include <bits/stdc++.h>

using namespace std;

int main()
{
    string str;
    map<int,int> bm, am;
    int num, day;
    char ch;
     
    while (getline(cin, str) && str.size() > 0) {
        stringstream s1(str);
        s1 >> num >> ch >> day;
        ++bm[num];
    }
    while (getline(cin, str)) {
        stringstream s2(str);
        s2 >> num >> ch >> day;
        ++am[num];
    }
    for (auto &it: bm) {
        if (am[it.first]) {
            cout << it.first << " " << it.second + am[it.first] << endl;
        }
    }
    return 0;
}