#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int main(){
	
	string s;
	bool flg = false;
	
	map<int,int> A;
	map<int,int> B;
	while(1){
		getline(cin,s);
		if(s=="#")break;
		if(cin.eof())break;
		
		if(s.size()<=1)flg=true;
		else{
			int a=0;
			rep(i,s.size()){
				if('0'<=s[i]&&s[i]<='9'){
					a*=10;
					a+=(s[i]-'0');
				}else{
					break;
				}
			}
			
			if(!flg)A[a]++;
			else B[a]++;
		}
	}
	
	typedef pair<int,int> pii;
	vector<pii> dat;
	
	map<int,int>::iterator it = A.begin();
	while(it!=A.end()){
		
		map<int,int>::iterator bt = B.find(it->first);
		if(bt!=B.end()){
			dat.push_back(pii(it->first, it->second+bt->second));
		}
		it++;
	}
	
	sort(dat.begin(),dat.end());
	
	rep(i,dat.size()){
		printf("%d %d\n",dat[i].first,dat[i].second);
	}
}