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

int main() {
    map<int, int> lastMonth;
    map<int, int> thisMonth;
    string line;
    while (getline(cin, line)) {
        if (line.empty()) {
            break;
        }
        istringstream buff(line.substr(0, line.find_first_of(',')));
        int num;
        buff >> num;
        lastMonth[num]++;
    }
    while (getline(cin, line)) {
        istringstream buff(line.substr(0, line.find_first_of(',')));
        int num;
        buff >> num;
        thisMonth[num]++;
    }
    for (map<int, int>::iterator it = lastMonth.begin(); it != lastMonth.end(); it++) {
        if (thisMonth[it->first] > 0) {
            cout << it->first << " " << it->second + thisMonth[it->first] << endl;
        }
    }
}