#include<iostream>
#include<string>
#include<sstream>

int data[2][1001];

int toInt(std::string str){
	std::stringstream z;
	int res;

	z << str;
	z >> res;

	return res;
}

int main(){

	int i = 0;
	std::string str;
	while (std::getline(std::cin, str)){
		if (str.find(',') == -1)i++;
		else data[i][toInt(str.substr(0, str.find(',')))]++;
	}

	for (int j = 0; j < 1001; j++){
		if (data[0][j] != 0 && data[1][j] != 0){
			std::cout << j << " " << data[0][j] + data[1][j] << std::endl;
		}
	}
	return 0;
}