#include <iostream>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	char s[10];
	vector<int> v1;
	while(gets(s) && *s != '\0') {
		v1.push_back(atoi(s));
	}
	vector<int> v2;
	while(cin >> s) {
		if(find(v1.begin(), v1.end(), atoi(s)) != v1.end()) {
			v2.push_back(atoi(s));
		}
	}
	map<int, int> m;
	rep(i,v2.size()) {
		auto it = m.find(v2[i]);
		if(it == m.end()) {
			m.insert(make_pair(v2[i], 1));
		} else {
			it->second++;
		}
	}
	rep(i,v1.size()) {
		auto it = m.find(v1[i]);
		if(it != m.end()) {
			it->second++;
		}
	}
	for(auto it = m.begin(); it != m.end(); ++it) {
		cout << (*it).first << " " << (*it).second << endl;
	}
	return 0;
}