#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

int sengetsu[101000][2];
int c;
string s;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(7);

    while (getline(cin, s))
    {
        if (s == "")
        {
            c++;
            if (c == 2)
                break;
            continue;
        }

        string T[2];
        T[0] = "";
        T[1] = "";
        int ok = 0;
        for (int i = 0; i < (int)s.size(); ++i)
        {
            if (s[i] == ',')
            {
                ok++;
            }
            else
            {
                T[ok] += s[i];
            }
        }
        int v;
        std::istringstream iss1(T[0]);
        iss1 >> v;
        sengetsu[v][c]++;
    }
    for (int i = 0; i < 99999; ++i)
    {
        if (sengetsu[i][0] >= 1 && sengetsu[i][1] >= 1)
        {
            cout << i << " " << sengetsu[i][0] + sengetsu[i][1] << endl;
        }
    }
    return 0;
}
