#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

vector<string> split(const string &s,char c){
	vector<string> ret;
	stringstream ss(s);
	string t;
	while(getline(ss,t,c)){
		ret.pb(t);
	}
	return ret;
}

int main(){
	map<int,int> m;
	set<int> s1,s2;
	bool f=0;
	string s;
	while(getline(cin,s)){
		if(/*s.end() - s.begin() == 1*/s==""){
			//o("ok");
			f=1; continue;
		}
		vector<string> v=split(s,',');
		int a=atoi(v[0].c_str());
		//o(a);
		m[a]++;
		if(!f) s1.insert(a);
		else s2.insert(a);
	}
	for(map<int,int>::iterator it=m.begin();it!=m.end();it++){
		//cout<<1<<endl;
		if(s1.count(it->fi) && s2.count(it->fi)) cout<<it->fi<<" "<<it->se<<endl;
	}

}