#include <iostream>
#include <sstream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#define n 1000
using namespace std;
int main(){
	string s;
	int a1[n],b1[n],a2[n],b2[n];
	int c1 = 0;
	int c2 = 0;
	while(1){
		getline(cin,s);
		if(s.size()==0) break;
		istringstream is(s);
		char d;
		is >> a1[c1] >> d >> b1[c1];
		c1++;
	}
	while(getline(cin,s)){
		istringstream is(s);
		char d;
		is >> a2[c2] >> d >> b2[c2];
		c2++;
	}
	bool e[c2];
	int a3[c2],b3[c2];
	int c3 = 0;
	for(int i=0;i<c2;i++) e[i] = false;
	for(int i=0;i<c2;i++){
		if(e[i]) continue;
		int s = 1;
		bool ex = false;
		for(int j=0;j<c1;j++){
			if(a2[i]!=a1[j]) continue;
			ex = true;
			s++;
		}
		if(not ex) continue;
		for(int j=i+1;j<c2;j++){
			if(a2[j]!=a2[i]) continue;
			e[j] = true;
			s++;
		}
		a3[c3] = a2[i];
		b3[c3] = s;
		c3++;
	}
	while(1){
		bool out = true;
		for(int i=0;i<c3-1;i++){
			if(a3[i]>a3[i+1]){
				out = false;
				int t = a3[i];
				a3[i] = a3[i+1];
				a3[i+1] = t;
				t = b3[i];
				b3[i] = b3[i+1];
				b3[i+1] = t;
			}
		}
		if(out) break;
	}
	for(int i=0;i<c3;i++) cout << a3[i] << " " << b3[i] << endl;
}