#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  map<int,int> mf,ms;
  string str;
  int cn,a,b;
  while(getline(cin,str),str.size()){
    stringstream ss;
    rep(i,str.size()){
      if(str[i]==',') str[i] = ' ' ;
    }
    ss << str;
    ss >> a;
    mf[a]++;
    ss.str("");
    
  }
  while(scanf("%d,%d",&a,&b)!=EOF){
    if(mf[a]!=0){
      if(ms[a]==0)ms[a]+=mf[a];
      ms[a]++;
    }
  }
  map<int,int>::iterator it = ms.begin();
  while(it!=ms.end()){
    cout << it->first << ' ' << it->second << endl;
    it ++;
  }
}