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

int main(){
	map<int,int> mp;
	map<int,int>::iterator it;
	string s;
	int a,b;
	while(getline(cin,s),!s.empty()){
		sscanf(s.c_str(),"%d %d",&a,&b);
		--mp[a];
	}
	while(cin>>s){
		sscanf(s.c_str(),"%d %d",&a,&b);
		it = mp.find(a);
		if(it!=mp.end()){
			if(it->second<0)it->second = 1-it->second;
			else ++it->second;
		}
	}
	for(it=mp.begin();it!=mp.end();++it){
		if(0<it->second)cout<<it->first<<' '<<it->second<<endl;
	}
	return 0;
}