#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int a[1010],b[1010];
int main()
{
	int t,h;
	char l;
	string s;
	while(getline(cin,s)&&s.size()!=0)
	{
		istringstream is1(s);
		is1 >> t >> l >> h;
		a[t]++;
	}
	while(getline(cin,s))
	{
		istringstream is2(s);
		is2 >> t >> l >> h;
		b[t]++;
	}
	for(int i=0;i<1010;i++)
	{
		if(a[i]&&b[i])
		{
			cout << i << ' ' << a[i]+b[i] << endl;
		}
	}
	return 0;
}