#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <cstdlib>
using namespace std;

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair

void solve() {
  string s;
  map<int,int> rc;
  set<int> b, a;
  
  while (1) {
    getline(cin, s);
    int l = s.find(',');
    if (l == -1) break;
    int lhs = atoi(s.substr(0,l).c_str());//, rhs = s.substr(l+1);
    if (rc.count(lhs)) {
      rc[lhs]++;
    } else {
      rc.insert(mp(lhs, 1));
    }
    b.insert(lhs);
  }
  
  while (getline(cin, s)) {
    int lhs = atoi(s.substr(0, s.find(',')).c_str());
    if (rc.count(lhs)) {
      rc[lhs]++;
    }
    a.insert(lhs);
  }
  
  map<int,int>::iterator it = rc.begin();
  while (it != rc.end()) {
    if (b.count(it->first) && a.count(it->first))
      cout<<it->first<<" "<<it->second<<endl;
    it++;
  }
}

int main (int argc, char const* argv[]) {
  solve();
  return 0;
}