#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif
 
int main(){
	std::vector<std::vector<int> > pcm(2);
	std::set<int> t;
	std::vector<int> t_vec;
	std::vector<int> counters;
	std::string buf;
	int idx = 0;
	int c;
	char tmp, d;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	while(std::getline(ifs, buf)){
#else
	while(std::getline(std::cin, buf)){
#endif
		if(buf == ""){
			idx++;
			continue;
		}
		std::istringstream stream(buf);

		stream >> c >> tmp >> d;
		pcm[idx].push_back(c);
	}
 
	for(int i = 0; i < pcm[0].size(); i++){
		for(int j = 0; j < pcm[1].size(); j++){
			if(pcm[0][i] == pcm[1][j]){
				t.insert(pcm[0][i]);
				break;
			}
		}
	}

	for(std::set<int>::iterator it = t.begin(); it != t.end(); it++){
		t_vec.push_back(*it);
	}

	std::sort(t_vec.begin(), t_vec.end());

	counters.resize(t_vec.size(), 0);

	for(int i = 0; i < t_vec.size(); i++){
		for(int j = 0; j < 2; j++){
			for(int k = 0; k < pcm[j].size(); k++){
				if(t_vec[i] == pcm[j][k]){
					counters[i]++;
				}
			}
		}
	}

	for(int i = 0; i < t_vec.size(); i++){
		std::cout << t_vec[i] << " " << counters[i] << std::endl;
	}

#if INPUT_FROM_FILE
	//fclose(fp);
#endif
    return 0;
}
