#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef pair<int,int> pii;

int stoi(string s){
	int num=0;
	rep(i,s.size()){
		num+=(int)(s[i]-'0')*pow(10,s.size()-1-i);
	}
	return num;
}

pii make(string s){
	string temp="";
	int num,cnt=1;
	rep(i,s.size()){
		if(s[i]==','){num=stoi(temp);break;}
		temp+=s[i];
	}
	return pii(num,cnt);
}

int main(){
	string s;
	int num=0,cnt,now=0;
	bool check=false;
	vector<pii> vec[2];
	while(getline(cin,s)){
		if(s==""){now=1;continue;}
		pii data=make(s);
		vec[now].push_back(data);
		num=0;
	}
	map<int,int> mp;
	rep(i,vec[0].size()){
		if(mp.find(vec[0][i].first)!=mp.end())mp[vec[0][i].first]+=vec[0][i].second;
		else mp[vec[0][i].first]=vec[0][i].second;
	}
	set<int> st;
	vector<int> kokyaku;
	rep(i,vec[1].size()){
		if(mp.find(vec[1][i].first)!=mp.end()){
			st.insert(vec[1][i].first);
			mp[vec[1][i].first]+=vec[1][i].second;
		}
	}
	for(set<int>::iterator ite=st.begin();ite!=st.end();ite++){
		kokyaku.push_back(*ite);
	}
	sort(kokyaku.begin(),kokyaku.end());
	rep(i,kokyaku.size()){
		cout<<kokyaku[i]<<" "<<mp[kokyaku[i]]<<endl;
	}
	return 0;
}