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

int main(){
	int a,b;
	int used[1000][2] = {};
	string s;
	bool flag = false,f = false;
	while(getline(cin,s)){
		if(s == "") flag = true;
		else{
			int tmp = 0;
			for(int i = 0;i < s.length();i++){
				if(s[i] == ',') {
					used[tmp - 1][flag]++;
					break;
				}else tmp = tmp * 10 + s[i] - '0';
			}
		}
	}
	for(int i = 0;i < 1000;i++){
		if(used[i][0] && used[i][1]) cout << i + 1 << " " << used[i][0] + used[i][1] << endl;
	}
	return 0;
}