#include <iostream>
#include <cstdlib>
using namespace std;

const int MAX_SUPPLIERS = 1000;

void Sort(int Array[], int array_num);
void Sort(int Array[][2], int arraynum);
bool BinarySearch(int target, int ar[], int array_num);
bool BinarySearch(int target, int ar[][2], int array_num);

int main()
{
	int lastmonth[MAX_SUPPLIERS],
		thismonth[MAX_SUPPLIERS],
		i=0, j=0, num[MAX_SUPPLIERS][2], samesupnum=0;
	while(true){
		char buf[1024], supplier[256];
		cin.getline(buf, sizeof(buf));
		if(buf[0] == '\0') break;
		for(int k=0; buf[k]!=','; k++){
			supplier[k] = buf[k];
			supplier[k+1] = ' ';
		}
		lastmonth[i] = atoi(supplier);
		for(int k=0; supplier[k] != ' '; k++){
			supplier[k] = ' ';
		}
		i++;
		cin.clear();
	}
	Sort(lastmonth, i);
	while(true){
		char buf[1024], supplier[256];
		cin.getline(buf, sizeof(buf));
		if(buf[0] == '\0') break;
		for(int k=0; buf[k]!=','; k++){
			supplier[k] = buf[k];
			supplier[k+1] = ' ';
		}
		thismonth[j] = atoi(supplier);
		for(int k=0; supplier[k] != ' '; k++){
			supplier[k] = ' ';
		}
		if(BinarySearch(thismonth[j], lastmonth, i)){
			if(!BinarySearch(thismonth[j], num, samesupnum)){
				num[samesupnum][0] = thismonth[j];
				samesupnum++;
				Sort(num, samesupnum);
			}
		}
		j++;
		cin.clear();
	}
	for(int k=0; k<samesupnum; k++){
		num[k][1] = 0;
		for(int l=0; l<i; l++){
			if(num[k][0] == lastmonth[l]) num[k][1]++;
		}
		for(int m=0; m<j; m++){
			if(num[k][0] == thismonth[m]) num[k][1]++;
		}
		cout << num[k][0] << " " << num[k][1] << endl;
	}
	return 0;
}

void Sort(int Array[], int arraynum)
{
	int tmp;
	for(int i=0; i<arraynum; i++){
		for(int j=i; j<arraynum; j++){
			if(Array[j] < Array[i]){
				tmp = Array[i];
				Array[i] = Array[j];
				Array[j] = tmp;
			}
		}
	}
}

void Sort(int Array[][2], int arraynum)
{
	int tmp;
	for(int i=0; i<arraynum; i++){
		for(int j=i; j<arraynum; j++){
			if(Array[j][0] < Array[i][0]){
				tmp = Array[i][0];
				Array[i][0] = Array[j][0];
				Array[j][0] = tmp;
			}
		}
	}
}

bool BinarySearch(int target, int ar[], int array_num)
{
	int L=0, R=array_num-1, M;
	while(L<=R){
		M = (L+R)/2;
		if(ar[M] == target) return true;
		else if(ar[M]<target)L=M+1;
		else R=M-1;
	}
	return false;
}

bool BinarySearch(int target, int ar[][2], int array_num)
{
	int L=0, R=array_num-1, M;
	while(L<=R){
		M = (L+R)/2;
		if(ar[M][0] == target) return true;
		else if(ar[M][0]<target)L=M+1;
		else R=M-1;
	}
	return false;
}