#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    int prev[1000] = {};
    int current[1000] = {};
    string in_str;
    while(getline(cin,in_str), in_str != "")
    {
        int c;
        int d;
        sscanf(in_str.c_str(),"%d,%d",&c,&d);
        prev[c - 1]++;
    }
    while(getline(cin,in_str) && in_str != "")
    {
        int c;
        int d;
        sscanf(in_str.c_str(),"%d,%d",&c,&d);
        current[c - 1]++;
    }
    for(unsigned int i = 0; i < 1000; i++)
    {
        if(prev[i] > 0 && current[i] > 0)
        {
            cout << i + 1 << " " << prev[i] + current[i] << endl;
        }
    }
    return 0;
}
