#include<iostream>
#include<string>
using namespace std;
string S;
int x[100000][2]; int c = 0;
int main() {
	while (getline(cin, S)) {
		if (S.size() == 0) { c++; }
		string T[2]; int ok = 0;
		for (int i = 0; i < S.size(); i++) {
			if (S[i] == ',') { ok++; }
			else { T[ok] += S[i]; }
		}
		x[stoi(T[0])][c]++;
	}
	for (int i = 0; i < 99999; i++) { if (x[i][0] >= 1 && x[i][1] >= 1) { cout << i << ' ' << x[i][0] + x[i][1] << endl; } }
	return 0;
}