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

int main()
{
    int c_before[1001], c_after[1001];
    int num, day;
    char p;

    for( int i = 1; i <= 1000; i++ )
        c_before[i] = 0;
    
    string str;
    while( getline( cin, str ) )
    {
        if( str == "" )
            break;
        if( str[1] == ',' )
            c_before[str[0]-'0']++;
        else if( str[2] == ',' )
            c_before[(str[0]-'0')*10+str[1]-'0']++;
        else if( str[3] == ',' )
            c_before[(str[0]-'0')*100+(str[1]-'0')*10+str[2]-'0']++;
        else if( str[4] == ',' )
            c_before[(str[0]-'0')*1000+(str[1]-'0')*100+(str[2]-'0')*10+str[3]-'0']++;
        else;
    }

    for( int i = 1; i <= 1000; i++ )
        c_after[i] = c_before[i];

    while( cin >> num >> p >> day )
        c_after[num]++;

    for( int i = 1; i <= 1000; i++ )
    {
        if( c_before[i] != 0 && c_before[i] != c_after[i] )
            cout << i << " " << c_after[i] << endl;
    }
    return 0;
}
