#include <iostream>
#include <string>
#include <map>
#include <sstream>
using namespace std;

int main() {
    map<int,int> cnt;
    int n, date;
    char c;
    string s;
    while (getline(cin, s), s != "") {
        stringstream ss(s);
        ss >> n >> c >> date;
        cnt[n] ++;
    }
    while (getline(cin, s), s != "") {
        stringstream ss(s);
        ss >> n >> c >> date;
        if (cnt.count(n)) {
            cnt[n] ++;
        }
    }
    map<int,int>::iterator it;
    for (it = cnt.begin(); it != cnt.end(); ++it) {
        if (2 <= it->second) {
            cout << it->first << " " << it->second << endl;
        }
    }
    return 0;
}