#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int getnum(string str){
  stringstream ss;
  ss<<str.substr(0,str.find_first_of(","));
  int ret;
  ss>>ret;
  return ret;
}
int ti[100000];
int main(void){
  string line;
  set<int> s1,s2;
  while(getline(cin,line)){
    if(line.size()==0) break;
    s1.insert(getnum(line)); 
    ti[getnum(line)]++;
  }
  while(getline(cin,line)){
    if(line.size()==0) break;
    s2.insert(getnum(line));
    ti[getnum(line)]++;
  }
  set<int>::iterator it = s1.begin();
  while(it!=s1.end()){
    if(s2.find(*it)!=s2.end()){
      printf("%d %d\n",*it,ti[*it]);
    }
    it++;
  }
  return 0;
}