#include <bits/stdc++.h>

using namespace std;

bool dealed[1010];
int cnt[1010] = {};
set<int> st;

int main() {
    string s;
    bool flag = false;

    while (getline(cin, s)) {
        if (s == "") {
            flag = true;
            continue;
        }

        int no;
        s = s.substr(0, s.find(','));
        no = atoi(s.c_str());
        if (flag) {
            if (st.find(no) != st.end()) dealed[no] = true;
        } else
            st.insert(no);
        cnt[no]++;
    }

    for (int i = 1; i <= 1000; i++) {
        if (!dealed[i]) continue;
        cout << i << " " << cnt[i] << endl;
    }

    return 0;
}
