#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef pair<double,double> P;
typedef complex<double> CP;
typedef long long ll;

string s;
int a[1100]={0},b[1100]={0};


int main(){
	while(getline(cin,s),s[0]!=13){
		int t1=0,t2=0;
		bool f=false;
		rep(i,s.size()){
			if(f){
			}
			else if(s[i]==','){
				break;
			}
			else{
				t1*=10;
				t1+=s[i]-'0';
				//cout<<t1<<endl;
			}
		}
		//cout<<t1<<endl;
		a[t1]++;
	}
	while(getline(cin,s)){
		int t1=0,t2=0;
		bool f=false;
		rep(i,s.size()){
			if(f){
			}
			else if(s[i]==','){
				break;
			}
			else{
				t1*=10;
				t1+=s[i]-'0';
			}
		}
		b[t1]++;
	}
	
	
	rep(i,1100){
		if(a[i]>0&&b[i]>0){
			cout<<i<<" "<<a[i]+b[i]<<endl;
		}
	}
	
	return 0;
}