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

int main(){
	string s;
	bool flag=false; //??????
	map<long,long> mp;
	set<long> thismonth; //????????????????????£??????
	
	while(getline(cin,s)){	
		if(s==""){
			flag=true; //??????
			continue;	
		}
		
		int point=0;
		while(s[point]!=',') point++;
		//printf("point = %d\n", point);
		
		string tmp=s.substr(0,point);
		//string b=s.substr(point+1, s.size()-1-point);
		
		//cout << a << " " << b <<endl;
		
		long a=stol(tmp);
		
		if(!flag){
			if(mp.find(a) == mp.end()) mp[a]=1;	
			else mp[a]++;
		}
		else{
			thismonth.insert(a);
			
			if(mp.find(a) == mp.end()){} //?????????????????????????????§??????	
			else mp[a]++;	
		}			
	}
	
	for(map<long,long>::iterator itr=mp.begin(); itr!= mp.end(); ++itr){
			if(thismonth.find(itr->first) != thismonth.end())
			cout << itr->first << " " << itr->second << endl;
	}
}