#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	char str[128];
	map<int, int> data;
	while(fgets(str, 128, stdin), str[0] != '\n'){
		int a, b;
		sscanf(str, "%d,%d", &a, &b);

		if(data.count(a))
			data[a]--;
		else
			data[a] = -1;
	}

	while(fgets(str, 128, stdin) != NULL){
		int a, b;
		sscanf(str, "%d,%d", &a, &b);
		if(data.count(a))
			data[a] = abs(data[a]) + 1;
	}

	for(map<int,int>::iterator itr = data.begin(); itr != data.end(); ++itr){
		if(itr->second < 0)
			continue;
		printf("%d %d\n", itr->first, itr->second);
	}

	return 0;
}