#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

int num;
string line;
map<int, int> m1, m2;

int main()
{
	while (getline(cin, line))
	{
		if (line == "") break;
		sscanf(line.c_str(), "%d", &num);
		m1[num]++;
	}

	while (getline(cin, line))
	{
		sscanf(line.c_str(), "%d", &num);
		m2[num]++;
	}

	for (map<int, int>::iterator it=m2.begin(); it!=m2.end(); it++)
	{
		if (m1[it->first] > 0)
		{
			cout << it->first << " " << m1[it->first] + it->second << endl;
		}
	}
	
	return 0;
}