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

int main(){
	string s;
	int n;
	map<int,int> mp;

	while(getline(cin, s) && !s.empty()){
		if(sscanf(s.c_str(), "%d", &n) == 1){
			mp[n] += 4;
			mp[n] |= 1;
		}
	}
	while(getline(cin, s) && !s.empty()){
		if(sscanf(s.c_str(), "%d", &n) == 1){
			mp[n] += 4;
			mp[n] |= 2;
		}
	}
	
	for(map<int,int>::iterator it = mp.begin(); it != mp.end(); ++it){
		if((it->second & 3) == 3){
			printf("%d %d\n", it->first, it->second >> 2);
		}
	}
}