#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

string s;
int a;
vector<int> vi1, vi2;
vector<P> v;

int changei(string s){
	int res;
	stringstream ss;
	ss << s;
	ss >> res;
	return res;
}

int main(){
	while (getline(cin, s)){
		if (s == "")break;
		string t = s.substr(0, s.find(","));
		a = changei(t);
		vi1.push_back(a);
	}
	while (getline(cin, s)){
		string t = s.substr(0, s.find(","));
		a = changei(t);
		vi2.push_back(a);
	}
	REP(i, vi1.size()){
		bool f = 0;
		int co = 0;
		REP(j, vi1.size()){
			if (vi1[i] == vi1[j])co++;
		}
		REP(j, vi2.size()){
			if (vi1[i] == vi2[j]){
				co++;
				f = 1;
			}
		}
		if (f){
			if (find(ALL(v), P(vi1[i], co)) == v.end()){
				v.push_back(P(vi1[i], co));
			}
		}
	}
	sort(ALL(v));
	REP(i, v.size()){
		cout << v[i].first << " " << v[i].second << endl;
	}
}