#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>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
 
 
const int INF = 1000000;


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;
}

 bool cmp(pair<string,int> p1,pair<string,int> p2){
 	return p1.fi.size(), p2.fi.size();
 }
 
 int main(){
 	map<string,int> m;
 	set<string> s1,s2;
 	bool f = false;
 	string s;
 	while(getline(cin,s)){
 		if (s == ""){
 			f = true;
 			continue;
 		}
 		vector<string> v = split(s,',');

 		m[v[0]]++;
 		if(!f) s1.insert(v[0]);
 		else s2.insert(v[0]);
 	}

 	vector<pair<string,int> > ans;

 	for(map<string,int>::iterator it = m.begin(); it != m.end(); it++){
 		if(s1.count(it->fi) && s2.count(it->fi)){
 			ans.pb(mp(it->fi,it->se));
 		}
 	}

 	sort(all(ans), cmp);

 	for(auto it = ans.begin(); it != ans.end(); it++){
 		cout<<it->fi<<" "<<it->se<<endl;
 	}
 }