#include<bits/stdc++.h>
#define rep(i,n)for(ll i=0;i<n;i++)
using namespace std;
typedef long long ll;

map<int, int>mp1, mp2;
int main() {
	string s;
	while (getline(cin, s), s != "") {
		int c; sscanf(s.data(), "%d,%*d", &c);
		mp1[c]++;
	}
	while (cin >> s) {
		int c; sscanf(s.data(), "%d,%*d", &c);
		mp2[c]++;
	}
	for (auto i : mp1) {
		if (mp2[i.first])
			cout << i.first << ' ' << i.second + mp2[i.first] << endl;
	}
	return 0;
}