#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

int main(){

	int num,date;
	map<int,int> m1;
	map<int,int> m2;
	string str;
	char buf[256];
	bool next=false;
	while(~scanf("%s",buf)){
		//if (str == "") next = true;
		sscanf(buf,"%d,%d",&num,&date);
		m1[num]++;
		
	}

	while(~scanf("%s",buf)){
		sscanf(buf,"%d,%d",&num,&date);
		if(m1[num] > 0){	
				if(m2[num] == 0) m2[num] = m1[num];
				m2[num]++;
			}
	}
	for(map<int,int>::iterator it = m2.begin(); it != m2.end(); it++){
		printf("%d %d\n",it->first,it->second);
	}
}