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

int first[1001],second[1001];

int main()
{
	string s;
	while(1){
		getline(cin,s);
		if(s.size() == 0) break;
		stringstream ss(s);
		int number;
		ss >> number;
		++first[number];
	}

	while(cin >> s){
		stringstream ss(s);
		int number;
		ss >> number;
		++second[number];
	}
	for(int i = 0; i < 1001; ++i){
		if(first[i] != 0 && second[i] != 0){
			cout << i << ' ' << first[i] + second[i] << endl;
		}
	}	
}