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

int main(){
	string input;
	bool lastMonth[10000];
	bool thisMonth[10000];
	int count[10000];

	fill(lastMonth, lastMonth+10000, false);
	fill(thisMonth, thisMonth+10000, false);
	fill(count, count+10000, 0);

	while(1){
		getline(cin, input);
		if(input.size() == 0) break;
		input[input.find(",", 0)] = '\0';
		lastMonth[atoi(input.c_str())] = true;
		count[atoi(input.c_str())]++;
	}
	while(cin >> input){
		input[input.find(",", 0)]  = '\0';
		thisMonth[atoi(input.c_str())] = true;
		count[atoi(input.c_str())]++;
	}
	for(int i=0; i < 10000; i++){
		if(lastMonth[i] && thisMonth[i]) cout << i << " " << count[i] << endl;
	}
}