#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>

using namespace std;

int main(void){
	vector<int> vId, vuId;
	map<int,int> mLastMonth, mCrrMonth;
	while(1){
		int id, day;
		char buf[32];
		
		cin.getline(buf,sizeof(buf)/sizeof(buf[0]));
		if( strlen(buf) == 0 )break;

		sscanf(buf, "%d,%d", &id, &day);
		mLastMonth[id]++;
		vId.push_back(id);
	}
	while(1){
		int id, day;
		string s;
		
		cin >> s;
		if( cin.eof() )break;

		sscanf(s.c_str(), "%d,%d", &id, &day);
		mCrrMonth[id]++;
	}
	sort( vId.begin(), vId.end() );
	vuId.resize(vId.size(),0);
	unique_copy( vId.begin(), vId.end(), vuId.begin() );
	for(unsigned int i = 0; i < vuId.size(); i++){
		if( mLastMonth[vuId[i]] > 0 && mCrrMonth[vuId[i]] > 0 ){
			cout << vuId[i] << ' ' << mLastMonth[vuId[i]] + mCrrMonth[vuId[i]] << endl;
		}
	}
	return 0;
}