#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <string>
using namespace std;

int main() {
	int a,b; string str;
	map<int,int> pre_m,post_m;
	map<int,int>::iterator mp;
	while(1)
	{
		getline(cin,str);
		if(str=="") break;
		string tmp="";
		int i=0;
		for( ;i<str.size();i++) if(str[i]==',') break; else tmp+=str[i];
		int TMP=atoi( tmp.c_str() );
		if(pre_m.find(TMP)==pre_m.end()) pre_m.insert(pair<int,int>(TMP,1));
		else pre_m[TMP]++;
	}
	while(scanf("%d,%d",&a,&b)!=EOF)
	{
		if(pre_m.find(a)==pre_m.end()) continue;
		if(post_m.find(a)!=post_m.end()) post_m[a]++;
		else post_m[a]=pre_m[a]+1;
	}
	for(mp=post_m.begin();mp!=post_m.end();mp++)
		cout << mp->first << ' ' << mp->second << '\n' ;
}