#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;

int main() {
  char buf[80];
  int n, d;
  map<int, P> m;
  map<int, P>::iterator it;
  while (fgets(buf, sizeof(buf), stdin) && (sscanf(buf, "%d,%d", &n, &d)==2)) {
    if ((it = m.find(n)) == m.end()) {
      m.insert(pair<int, P>(n, P(1, 1)));
    } else {
      ++(it->second.first);
    }
  }
  while (fgets(buf, sizeof(buf), stdin) && (sscanf(buf, "%d,%d", &n, &d)==2)) {
    if ((it = m.find(n)) != m.end()) {
      ++(it->second.first);
      ++(it->second.second);
    }
  }
  for (it=m.begin(); it!=m.end(); it++) {
    if (it->second.second > 1) {
      printf("%d %d\n", it->first, it->second.first);
    }
  }
  return 0;
}