#include <iostream>
#include <map>
#include <string>
#include <sstream>
using namespace std;
typedef long long ll;
#define mp make_pair

ll s2i(string s) {
	stringstream ss(s);
	ll l;
	ss>>l;
	return l;
}

map<ll,int> prev;

void solve() {
	string str;
	bool mode = true;
	while (getline(cin, str)) {
		if (str == "") {
			mode = false;
			continue;
		}
		
		string id = "";
		ll lid;
		if (mode) {
			for (int i = 0; i < str.size(); i++) {
				if (str[i] == ',') {
					break;
				}
				id += str[i];
			}
			lid = s2i(id);
			if (prev.count(lid) == 0) {
				prev.insert(mp(lid, 1));
			} else {
				prev[lid]++;
			}

		} else {
			for (int i = 0; i < str.size(); i++) {
				if (str[i] == ',') {
					break;
				}
				id += str[i];
			}
			lid = s2i(id);
			if (prev.count(lid) >= 1) {
				prev[lid]++;
			}
		}
	}

	
	map<ll,int>::iterator it = prev.begin();
	while (it != prev.end()) {
		if (it->second > 1)
			cout<<it->first<<" "<<it->second<<endl;
		it++;
	}
	
}

int main(int argc, const char *argv[]) {
	solve();
	return 0;
}