#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
        int list[2][1000];
        for(int i = 0; i < 2; i++){
                for(int j = 0; j < 1000; j++){
                        list[i][j] = 0;
                }   
        }   
        char s[100];
        int c = 0;
        while(cin.getline(s,100)){
                if(s[0] !=  '\0'){
                        int n = 0;
                        int i = 0;
                        while(s[i] != ','){
                                n = n*10+s[i++]-'0';
                        }   
                        list[c][n-1]++;
                }else c++;
        }   
        for(int i = 0 ; i < 1000; i++){
                if(list[0][i] && list[1][i]) cout << i+1 <<" "<< list[0][i]+list[1][i] << endl;
        }   
}