
#include<iostream>
#include<string>
using namespace std;

int main() {
	
	int ky[1000] = {};
	int ny[1000] = {};
	string s;
	while (cin>>s&&s.empty()) {
		int it=1;
		for (int i = 0;i<s.size();i++) {
			if (s[i] == ',') {
				it = i;
				break;
			}
		}

		string a;
		a = s.substr(0, it);
		int c = stoi(a);
		ky[c - 1]++;

	}

	string sa;
	while (cin >> sa) {
		int it;
		for (int i = 0;i<sa.size();i++) {
			if (sa[i] == ',') {
				it = i;
				break;
			}
		}

		string a;
		a = sa.substr(0, it);
		int c = stoi(a);

		ny[c - 1]++;
	}

	for (int i = 0;i<1000;i++) {
		if (ky[i] != 0 && ny[i] != 0)cout << i + 1 << ' ' << ky[i] + ny[i] << endl;
	}
	return 0;
}