#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	string str;
	int no, date;
	map<int, int> m;
	map<int, int> ans;
	while (1) {
		getline(cin, str);
		if (str == "")
			break;
		sscanf(str.c_str(), "%d,%d", &no, &date);
		if (m.find(no) == m.end())
			m[no] = 1;
		else
			m[no]++;
	}
	while (getline(cin, str)) {
		sscanf(str.c_str(), "%d,%d", &no, &date);
		if (m.find(no) != m.end())
			ans[no] = m[no] = m[no] + 1;
	}
	map<int, int>::iterator it = ans.begin();
	while (it != ans.end()) {
		cout << it->first << " " << it->second << endl;
		it++;
	}
	return 0;
}