#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<regex>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int number1[1000] = {0};
    int number2[1000] = {0};
    string s;

    while(1){
        getline(cin ,s);
        if(s.empty()) break;
        int it = stoi( s.substr(0, s.find(',') ) );
        number1[it]++;
    }
    while(1){
        getline(cin, s);
        if(s.empty()) break;
        int it = stoi( s.substr(0, s.find(',') ) );
        if(number1[it] != 0){
            number2[it] += number1[it];
            number1[it] = 0;
        }
        number2[it]++;
    }
    rep(i,1000){
        if(number2[i] != 0){
            cout << i << ' ' << number2[i] << endl;
        }
    }
}