#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

struct Info
{
	int d;
	int m;
	int cnt;

	Info()
	{
		cnt = 0;
		d = -1;
	}
};

int main()
{
	string s;
	map<int, Info> m;
	int mon = 0;

	while (getline(cin, s))
	{
		if (s == "")
		{
			mon = 1;
			continue;
		}
		stringstream ss;
		ss << s;

		int c, d;
		ss >> c;
		ss.ignore();
		ss >> d;

		if (mon == 0)
		{
			m[c].m = 0;
			if (m[c].d == -1)
			{
				m[c].d = d;
			}
			m[c].cnt++;
		}
		else
		{
			if (m.count(c))
			{
				if ((m[c].m == 0 && m[c].d >= d) || (m[c].m == 1 && m[c].d <= d))
				{
					m[c].m = 1;
					m[c].d = d;
					m[c].cnt++;
				}
			}
		}
	}

	for (auto i : m)
	{
		if (i.second.m == 1)
		{
			cout << i.first << " " << i.second.cnt << endl;
		}	
	}
}
