#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
using namespace std;

int main() {
	int n,k;
	char s[256];
	map<int,int> da1,da2;
	map<int,int>::iterator it;
	while(true) {
		n=atoi(gets(s));
		if (strlen(s)==0) break;
		if (da1.find(n)!=da1.end()) da1[n]++; else da1.insert(map<int,int>::value_type(n,1)); 
	}
	while(scanf("%d,%d",&n,&k)!=EOF) {
		if (da1.find(n)!=da1.end()) {
			if (da2.find(n)!=da2.end()) da2[n]++; else da2.insert(map<int,int>::value_type(n,da1[n]+1));
		}
	}
	for (it=da2.begin();it!=da2.end();it++) cout << (*it).first << ' ' << (*it).second << endl;    
    return 0;
}