#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	int a[1001] = {};
	int b[1001] = {};
	for (string s; getline(cin, s) && s != "";) {
		stringstream ss(s);
		int p, q; char c;
		ss >> p >> c >> q;
		a[p]++;
	}
	for (string s; getline(cin, s) && s != "$";) {
		stringstream ss(s);
		int p, q; char c;
		ss >> p >> c >> q;
		b[p]++;
	}
	for (int i = 0; i < 1001; i++) {
		if (a[i] > 0 && b[i] > 0)
			cout << i << " " << a[i] + b[i] << endl;
	}

	return 0;
}