#include<iostream>
#include<vector>
#include<map>
using namespace std;

int main() {
	vector<int>l;
	vector<int>k;

	int a, b;
	while (scanf("%d,%d", &a, &b)) {
		int flg = 1;
		for (int i = 0;i < l.size();i++) {
			if (a == l[i]) {
				k[i]++;
				flg = 0;
				break;
			}
		}
		if (flg == 1) {
			l.push_back(a);
			k.push_back(0);
		}
	}

	int c, d;
	vector<int>v;
	vector<int>n;
	while (scanf("%d,%d", &c, &d)) {
		for (int i = 0;i < l.size();i++) {
			if (c == l[i]) {
				v.push_back(c);
				n.push_back(k[i]+1);
			}
		}
	}

	map<int, int>m;
	for (int i = 0;i < v.size();i++) {
		m.insert(make_pair(v[i], n[i]));
	}

	for (auto itr = m.begin();itr != m.end();itr++) {
		cout << itr->first << ' ' << itr->second << endl;
	}
	return 0;
}