#include<iostream>
#include<string>
#include<map>
#include<cstdlib>

using namespace std;

int main(){
	string in;
	map<int,int> c,d;
	map<int,int>::iterator p;
	
	while(getline(cin,in)){
		if(in.size()==1)break;
		int n=atoi(in.c_str());
		p=c.find(n);
		if(c.end()==p)c.insert(pair<int,int>(n,1));
		else ++(p->second);
		in.clear();
	}
	in.clear();
	
	while(getline(cin,in)){
		if(in.size()==1)break;
		int n=atoi(in.c_str());
		p=d.find(n);
		if(d.end()==p)d.insert(pair<int,int>(n,1));
		else ++(p->second);
		in.clear();
	}
	
	
	for(p=c.begin();p!=c.end();++p){
		map<int,int>::iterator q=d.find(p->first);
		if(q!=d.end()){
			cout<<(p->first)<<" "<<(p->second+q->second)<<endl;
		}
	}
	return 0;
}