#include <iostream>
#include <cstdio>
#include <map>

using namespace std;

int main()
{
    map<int, int> ans;
    map<int, int> chk;
    char ch;
    bool flag = false, fst = true;


    while ((ch = getchar()) != EOF) {
        if (ch == '\n') 
            fst = false;
        else {
            int id;
            id = ch - '0';
            
            while ((ch = getchar()) != ',') {
                id *= 10;
                id += ch - '0';
            }
            while ((ch = getchar()) != '\n')
                ;

            ans[id]++;
            if (fst && chk.count(id) == 0) 
                chk[id]++;
            else if (!fst && chk.count(id) != 0 && chk[id] == 1) 
                chk[id]++;
        }
    }
        

    map<int, int>::iterator it = ans.begin();
    while (it != ans.end()) {
        if (chk[(*it).first] == 2)
            cout << (*it).first << " " << (*it).second << endl;
        it++;
    }

    return 0;
}