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

int main(){
    int companies[2001][2], n, d;
    string in;
    memset( companies, 0, sizeof(companies) );
    while( getline(cin, in) ){
        if( in.length() == 0 )  break;
        sscanf( in.c_str(), "%d,%d", &n, &d );
        companies[n][0]++;
    }
    while( getline(cin, in) ){
        sscanf( in.c_str(), "%d,%d", &n, &d );
        companies[n][1]++;
    }
    for( int i=0; i<=2000; i++ ){
        if( companies[i][0] && companies[i][1] ){
            printf("%d %d\n", i, companies[i][0]+companies[i][1]);
        }
    }
    return 0;
}