#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, string>
const int INF = INT_MAX / 2;
const int N = 100;


P split(string str){
    stringstream ss(str);
    string tmp;
    P ret;
    getline(ss, tmp, ',');
    ret.first = atoi(tmp.c_str());
    getline(ss, ret.second, ',') ;
    return ret;
}

int main(){
    string str;
    map<int, pair<int, int> > m;
    while(getline(cin, str) && str != ""){
        P tmp = split(str);
        m[tmp.first].first++;
    }
    while(getline(cin, str)){
        P tmp = split(str);
        m[tmp.first].second++;
    }
    vector< pair<int, int> > ans;
    for(map<int, pair<int, int> >::iterator it = m.begin(); it != m.end(); it++){
        int No = (*it).first, a = (*it).second.first, b = (*it).second.second;
        if(a != 0 && b != 0) ans.push_back( pair<int, int>(No, a + b) );
    }
    sort(ans.begin(), ans.end());
    REP(i, ans.size()) cout <<ans[i].first <<" " <<ans[i].second <<endl;
    return 0;
}