#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>

using namespace std;

struct Trading {
    int cnt;
    bool check[2];
} trad[1001];

int main() {
    int c, mode = 0;
    string s;
    while (getline(cin, s)) {
        if (s == "") {
            mode++;
            continue;
        }
        sscanf(s.data(), "%d", &c);
        trad[c].cnt++;
        trad[c].check[mode] = true;
    }
    for (int i = 1; i < 1001; i++) {
        if (trad[i].check[0] && trad[i].check[1]) {
            cout << i << " " << trad[i].cnt << endl;
        }
    }
    
    return 0;
}