#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

int main() {

    map<int, int> trades;
    map<int, bool> cont;
    
    string line;
    while(true) {
        getline(cin, line);
        if (line == "") break;

        istringstream is (line);
        int n, c;
        char comma;
        is >> n >> comma >> c;

        trades[n] += 1;
    }

    while(getline(cin, line)) {
        istringstream is (line);
        int n, c;
        char comma;
        is >> n >> comma >> c;
        
        if (trades[n] >= 1)  {
            trades[n] += 1;
            cont[n] = true;
        }
    }

    map<int, int>::iterator itr;
    for(itr = trades.begin(); itr != trades.end(); itr++) {
        if (cont[itr->first]) {
            cout << itr->first << " " << itr->second << endl;
        }
    }

    
    return 0;
}