#include<bits/stdc++.h>
using namespace std;
int c; string s;
void f() {
	int flag = 0; c = 0;
	for (char ch : s) {
		if (ch == ',')return;
		c *= 10; c += ch - '0';
	}
}
int a[1100], b[1100]; set<int>st;
signed main() {
	int flag = 0;
	while (getline(cin, s)) {
		if (s == "")flag++;
		else {
			f();
			a[c]++;
			if (!flag)st.insert(c);
			else if (st.count(c))b[c] = 1;
		}
	}
	for (int t : st)if (b[t])cout << t << ' ' << a[t] << endl;
}
