#include <iostream>
#include <cstdio>
#include <map>
#include <string>

using namespace std;

int ID(string str){
	int num = 0;
	for(int i = 0; i < 500; i++){
		if(str[i] == ','){
			break;
		}
		num *= 10;
		num += (str[i] - '0');
	}
	return num;
}

// ??????????????§??????????????¢?´¢?????????????????????

int main(){
	
	map<int, int> m;
	map<int, int>::iterator ite;
	
	string str;
	int id;
	
	while(true){
		getline(cin, str);
		if(str.size() == 0){
			break;
		}
		id = ID(str);
		ite = m.find(id);
		if(ite != m.end()){
			ite -> second++;
		}else{
			m.insert(make_pair(id, 1));
		}
	}
	
	while(true){
		cin >> str;
		if(cin.eof()){
			break;
		}
		id = ID(str);
		ite = m.find(id);
		if(ite != m.end()){
			if(ite -> second < 10000){
				ite -> second += 10000;
			}
			ite -> second++;
		}
	}
	
	for(ite = m.begin(); ite != m.end(); ite++){
		if(ite -> second > 10000){
			cout << ite -> first << " " << ite -> second - 10000 << endl;
		}
	}
	
	return 0;
}