#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int c, d;	string s;
	int ans[1001][2];
	for (int i = 0; i < 1001; i++) {
		ans[i][0] = ans[i][1] = 0;
	}
	while (getline(cin, s), s != "")
		rep(i, s.size()) {
		if (s[i] == ',') { s[i] = ' '; }

		stringstream ss(s);
		ss >> c >> d;
		ans[c][0]++;
	}
	while (getline(cin, s), s != "")
		rep(i, s.size()) {
		if (s[i] == ',') { s[i] = ' '; }

		stringstream ss(s);
		ss >> c  >> d;
		ans[c][1]++;
	}
	for (int i = 1; i <= 1000; i++) {
		if (ans[c][0] > 0 && ans[c][1] > 0) {
			cout << i << " " << ans[c][0]+ans[c][1] << endl;
		}
	}
	return 0;
}
