#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef pair<int, int> P;
typedef long long int ll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n,m;
int num[100000];
char a;
string str;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(getline(cin,str)){
		if(str.size() == 0) break;
		int tmp = 0;
		rep(i,str.size()){
			if(str[i] == ','){
				num[tmp]++;
				break;
			}
			tmp = tmp*10+str[i]-'0';
		}
	}
	rep(i,100000) num[i] *= 10000;
	while(getline(cin,str)){
		int tmp = 0;
		rep(i,str.size()){
			if(str[i] == ','){
				if(num[tmp] >= 10000) num[tmp]++;
				break;
			}
			tmp = tmp*10+str[i]-'0';
		}
	}
	rep(i,100000){
		if(num[i] >= 10000 && num[i]%10000 != 0){
			cout << i << " " << (num[i]/10000)+(num[i]%10000) << endl;
		}
	}
}