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

int main(){
	
	map<int,int>bef;
	map<int,int>aft;
	
	int cnt=0;
	char c;
	int name=0;
	int seco=0;
	while(scanf("%c",&c)!=EOF){
		if(c=='\n'){
			name=0;
			if(cnt)seco=1;
			else cnt=1;
		}
		else{
			cnt=0;
			if(c==','){
				if(seco){
					aft[name]++;
				}else{
					bef[name]++;
				}
			}else{
				name*=10;
				name+=(c-'0');
			}
		}
	}
	
	map<int, int>::iterator it = bef.begin();
	while( it != bef.end() ){
		if(aft[(*it).first]){
			cout << (*it).first << " " << (*it).second+aft[(*it).first] << endl;
		}
		++it;
	}
	
	
	
	return 0;
}
