#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <tuple>
#include <set>
#include <functional> 
#include <string.h>

#define X first
#define Y second
#define MP make_pair
#define MT make_tuple
#define FOR(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REP(i, a, n) for(int (i) = (a); (i) < (n); (i)++)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll > pll;
using namespace std;
const int MAX = 101;
const double PI = 3.1415926535897932384;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

int TakeCustomNum(string s){
	int val = 0, digit = 10;
	FOR(i, s.size()){
		if (s[i] == ',') break;
		else{
			val *= digit;
			val += s[i] - '0';
		}
	}
	return val;
}

void InputLastData(map<int, int> &ans){
	string s;
	while (getline(cin, s) && s != "\0"){
		ans[TakeCustomNum(s)]++;
	}
}

void TakeCommonData(map<int, int> &prev, map<int, int> &now){
	string s;
	while (getline(cin, s) && s != "\0"){
		int key = TakeCustomNum(s);

		if (now.count(key)) now[key]++;
		else if (prev.count(key)) now[key] += prev[key] + 1;
	}
}

void OutputData(map<int, int> &ans){
	for(auto i: ans){
		if (i.second > 1){
			cout << i.first << " " << i.second << endl;
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	map<int, int> prev, now;
	
	InputLastData(prev); 
	TakeCommonData(prev, now);

	OutputData(now);

	return 0;
}