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

int a[1005], b[1005];
int main(){
	string str;
	int tmp;
	fill(a, a+1005, 0);
	fill(b, b+1005, 0);
	while(getline(cin, str)){
		if(str == "")break;
		tmp = atoi(str.substr(0, str.find(",")).c_str());
		a[tmp]++;
	}
	while(getline(cin, str)){
		if(str == "a")break;
		tmp = atoi(str.substr(0, str.find(",")).c_str());
		b[tmp]++;
	}
	for(int i = 0;i < 1005;i++){
		//if(a[i])cout << a[i] << endl;
		if(a[i] && b[i])cout << i << " " << a[i]+b[i] << endl;
	}
	return 0;
}