#include<iostream>
#include<map>
#include<cstdlib>
#include<string>
#define all(c) (c).begin(),(c).end()
using namespace std;
typedef pair<int,int> P;
int main(){
	int x,y;
	char c;
	string s;
	map<int,int> box,arr;
	map<int,int>::iterator ite;
	while(getline(cin,s),s.size()!=0){
		x=atoi(s.c_str());
		if(box.find(x)==box.end())
			box.insert(P(x,1));
		else
			box[x]++;
		
	}
	while(getline(cin,s),s.size()!=0){
		x=atoi(s.c_str());
		if(box.find(x)!=box.end()){
			if(arr.find(x)!=arr.end())
				arr[x]++;
			else{
				arr.insert(P(x,1+box[x]));
			}
		}
		
	}
	for(ite=arr.begin();ite!=arr.end();ite++)
		cout<<ite->first<<' '<<ite->second<<endl;
	return 0;
}