#include<iostream>
#include<cctype>
#include<cstdlib>
#include<map>
using namespace std;

int main()
{
	map<int, int> num;
	map<int, int>::iterator it;
	int i;
	char c;
	char s[1000000];
	while (cin.get(c)) {
		if (!isdigit(c)) {
			break;
		}

		i = 0;
		s[i++] = c;
		while ( cin.get(c) ) {
			if (!isdigit(c)) break;
			s[i++] = c;
		}
		s[i] = '\0';
		num[atoi(s)] --;

		i = 0;
		while ( cin.get(c) ) {
			if (!isdigit(c)) break;
			s[i++] = c;
		}
		s[i] = '\0';

		cin.ignore(0xff, '\n');
	}
	while (cin.get(c)) {
		if (!isdigit(c)) {
			cin.ignore(0xff, '\n');
			break;
		}

		i = 0;
		s[i++] = c;
		while ( cin.get(c) ) {
			if (!isdigit(c)) break;
			s[i++] = c;
		}
		s[i] = '\0';
		num[atoi(s)] = abs(num[atoi(s)]) + 1;

		i = 0;
		while ( cin.get(c) ) {
			s[i++] = c;
		}
		s[i] = '\0';

		cin.ignore(0xff, '\n');
	}
	for (it = num.begin(); it != num.end(); it++) {
		if ((*it).second > 0) cout<<(*it).first<<" "<<(*it).second<<endl;
	}
	return 0;
}