#include <cstdio>
#include <cstdlib>
#include <map>
#include <utility>
using namespace std;
typedef pair<int, int> P;

int main()
{
	map<int, P> biz;
	char str[32];
	char *p;
	int month = 1;
	
	while ((*str = getchar()) != EOF){
		if (*str == '\n'){
			month++;
			continue;
		}
		p = str + 1;
		while ((*(p++) = getchar()) != '\n');
		int id, day;
		sscanf(str, "%d,%d", &id, &day);
		
		biz[id].first++;
		if (biz[id].second < month) biz[id].second += month;
	}
	for (map<int, P>::iterator i = biz.begin(); i != biz.end(); i++){
		if (i->second.second == 3) printf("%d %d\n", i->first, i->second.first);
	}
	
	return 0;
}