#include<iostream>
using namespace std;
int R[100000][2], a, b, p ,x[1000000], y[1000000]; char c;
int main() {
	while (cin >> a >> c >> b && p<6) {
		R[p][0] = a;
		R[p][1] = b;
		p++;
	}
	for (int i = 0; i < p / 2; i++) {
		x[R[i][0]] += 1;
	}
	for (int i = p / 2; i < p; i++) {
		y[R[i][0]] += 1;
	}
	for (int i = 0; i < 1000000; i++) {
		if (y[i] > 0 && x[i]>0) {
			cout << i << ' ' << x[i] + y[i] << endl;
		}
	}
}