#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

typedef struct{
    int id;
    int trade1;
    int trade2;
} trio;

bool operator<( const trio& l, const trio& r ){
    return l.id < r.id;
}

trio gen(int id, int trade1){
    trio n;
    n.id = id;
    n.trade1 = trade1;
    n.trade2 = 0;
    return n;
}

typedef vector< trio > P;

int main(){
    int n, d;
    char command[32];
    P pp;
    while( fgets(command, 32, stdin)){
        if( command[0] == '\n' ) break;
        sscanf(command, "%d,%d", &n, &d);
        P::iterator it = pp.begin();
        for(; it != pp.end(); it++){
            if( it->id == n ){
                (it->trade1)++;
                break; 
            }
        }
        if( it == pp.end() ){
            pp.push_back( gen(n, 1) );
        }
        n = 0; d = 0;
    }
    while( scanf("%d,%d", &n, &d) != EOF ){
        P::iterator it = pp.begin();
        for(; it != pp.end(); it++){
            if( it->id == n ){
                (it->trade2)++;
                break; 
            }
        }
    }
    sort(pp.begin(), pp.end());
    for(P::iterator it = pp.begin(); it != pp.end(); it++){
        if( it->trade1 && it->trade2 ){
            printf("%d %d\n", it->id, it->trade1 + it->trade2);
        }
    }
    return 0;
}