#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;

// ツ閉カツ篠堋療アsツづーツ閉カツ篠喞ツ凝ヲツ静伉づィツづ閉ェツ環つオツづ陛板つキ
vector<string> split_string(string s, char c){
	string str;
	vector<string> vs;
	s.push_back( c );
	
	for(int i=0 ; i < s.size() ; i++ ){
		if( s[i] == c ){
			if( !str.empty() ){
				vs.push_back( str );
				str.clear();
			}
		}else{
			str.push_back( s[i] );
		}
	}
	return vs;
}

// stringツづーintツづ可陛渉環キ
int s_to_i(string s){
	int n=0;
	for(int i=0 ; i < s.size() ; i++ ){
		n *= 10;
		n += s[i] - '0';
	}
	return n;
}

int main(){
	string s;
	bool flag = false;
	map<int,bool> month1, month2;
	vector<int> v;
	
	while( getline(cin,s) ){
		int id;
		
		// ツ凝ウツ板陳行ツづ個づつォ
		if( s.empty() ){
			flag = true;
			continue;
		}else{
			vector<string> vs = split_string( s , ',' );
			id = s_to_i( vs[0] );
		}
		
		if( flag == false ){
			month1[id] = true;
			v.push_back( id );
		}else{
			month2[id] = true;
			v.push_back( id );
		}
	}
	
	vector<P> vp;
	for(map<int,bool>::iterator it = month1.begin() ; it != month1.end() ; ++it ){
		int id = it->first;
		if( month2.count(id) ){
			int cnt = count( v.begin() , v.end() , id );
			P p( id , cnt );
			vp.push_back( p );
		}
	}
	sort( vp.begin() , vp.end() );
	for(int i=0 ; i < vp.size() ; i++ ){
		cout << vp[i].first << " " << vp[i].second << endl;
	}
}