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

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