#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <cstdio>
using namespace std;

int main(void)
{
	map <int, int> mf, ms;
	string str;
	int cn, a, b;
	while (getline(cin, str), str.size() != 0){
		stringstream ss;
		for (int i = 0; i < str.size(); i++){
			if (str[i] == '.') str[i] = ' ';
		}
		ss << str;
		ss >> a;
		mf[a]++;
		ss.str("");
	}
	while (scanf("%d,%d", &a, &b) != EOF){
		if (mf[a] != 0){
			if (ms[a] == 0) ms[a] += mf[a];
			ms[a]++;
		}
	}
	
	map <int, int> ::iterator it = ms.begin();
	while (it != ms.end()){
		cout << it->first << " " << it->second << endl;
		it++;
	}
	
	return 0;
}