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

struct data{
	int id;
	int c1, c2;
};

bool comp(data d1, data d2){
	return d1.id < d2.id;
}

int index(char c){
	return (int)c - (int)'0';
}

int get_num(vector<int> vi){
	int n = 1;
	int c = 0;
	for(vector<int>::reverse_iterator iter = vi.rbegin();
		iter != vi.rend(); iter++)
	{
		c += n * index(*iter);
		n = n * 10;
	}
	return c;
}

int main(){
	vector<data> vd;
	int id;
	int day;
	string s;
	char c;
	while(getline(cin, s)){
		if(s == "") break;
		vector<int> vi;
		data d;
		string::iterator iter = s.begin();
		while(isdigit(*iter)) vi.push_back(*(iter++));
		d.id = get_num(vi);
		d.c1 = 1;
		d.c2 = 0;
		vi.clear();
		vector<data>::iterator vditer = vd.begin();
		while(vditer != vd.end() && (*vditer).id != d.id) vditer++;
		if(vditer == vd.end()) vd.push_back(d);
		else (*vditer).c1++;
	}
	while(cin >> id >> c >> day){
		vector<data>::iterator vditer = vd.begin();
		while(vditer != vd.end() && (*vditer).id != id) vditer++;
		if(vditer != vd.end()) (*vditer).c2++;
	}
	sort(vd.begin(), vd.end(), comp);
	for(vector<data>::iterator iter = vd.begin();
		iter != vd.end(); iter++)
	{
		if((*iter).c1 != 0 && (*iter).c2 != 0){
			cout << (*iter).id << " " << (*iter).c1 + (*iter).c2 << endl;
		}
	}
	return 0;
}