#include <iostream>
#include <sstream>
#include <string>
#define n 100000

using namespace std;

int main(){
	int a[n];
	for(int i=0;i<n;i++) a[i] = 0;
	string s;
	int b,d;
	char c;
	while(1){
		getline(cin,s);
		if(s.size()==0) break;
		istringstream ss(s);
		ss >> b >> c >> d;
		a[b]--;
	}
	while(cin >> b >> c >> d){
		if(a[b]<0) a[b] = -a[b];
		a[b]++;
	}
	for(int i=0;i<n;i++) if(a[i]>0) cout << i << " " << a[i] << endl;
}