#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;

int main(){
	string s;
	vector<vector<int> > cd(2, vector<int>(1001, 0));
	int step = 0;
	while(getline(cin, s)){
		if(s == ""){
			step++;
			continue;
		}
		replace(s.begin(), s.end(), ',', ' ');
		stringstream buf(s);
		int c, d;
		buf >> c >> d;
		cd[step][c]++;
	}
	for(int i=0; i<=1000; i++){
		if(cd[0][i]!=0 && cd[1][i]!=0){
			cout << i << " " << cd[0][i]+cd[1][i] << endl;
		}
	}
	return 0;
}
