#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;

int main() {
	vector<int> com1_cus_num;
	vector<int> com1_day;
	vector<int> com2_cus_num;
	vector<int> com2_day;
	vector<int> tra_same_com;
	vector<int> tra_nums;
	int tmp_cus_num,tmp_day,tra_num;
	//??\?????????
	while (scanf("%d,%d", &tmp_cus_num, &tmp_day)!=EOF) {
		com1_cus_num.push_back(tmp_cus_num);
		com1_day.push_back(tmp_day);
	}
	while (scanf("%d,%d", &tmp_cus_num, &tmp_day)!=EOF) {
		com2_cus_num.push_back(tmp_cus_num);
		com2_day.push_back(tmp_day);
	}
	//?????°check
	for (int i = 0; i < com1_cus_num.size(); i++) {
		tra_num = 1;
		for (int j = 0; j < com2_cus_num.size(); j++) {
			if (com1_cus_num[i] == com2_cus_num[j])tra_num++;
		}
		if (tra_num >= 2) {
			tra_same_com.push_back(com1_cus_num[i]);
			tra_nums.push_back(tra_num);
		}
	}
	//??????
	for (int i = 0; i < tra_same_com.size(); i++) {
		cout << tra_same_com[i] << ' ' << tra_nums[i] << endl;
	}
}