#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int t_1[1001] = {}, t_2[1002] = {};
    int c1, c2;
    string s;
    while (getline(cin, s), s != "")
    {
        rep(i, s.size()) if (s[i] == ',') s[i] = ' ';
        stringstream ss(s);
        ss >> c1 >> c2;
        t_1[c1]++;
    }
    while (getline(cin, s))
    {
        rep(i, s.size()) if (s[i] == ',') s[i] = ' ';
        stringstream ss(s);
        ss >> c1 >> c2;
        t_2[c1]++;
    }

    rep(i, 1001)
    {
        if (t_1[i] > 0 && t_2[i] > 0)
            cout << i << " " << t_1[i] + t_2[i] << endl;
    }
    return 0;
}
