#include <cstdio>
#include <map>
#include <set>

using namespace std;

int main() {
  char s[32];
  int i, d;
  bool f(false);
  map<int, int> cs;
  set<int> is;
  while (fgets(s, 32, stdin)) {
    if (sscanf(s, "%d,%d\n", &i, &d) != 2) {
      f = true;
      continue;
    }
    if (f && cs[i])
      is.insert(i);
    cs[i]++;
  }
  for (set<int>::iterator it = is.begin(); it != is.end(); ++it)
    printf("%d %d\n", *it, cs[*it]);
  return 0;
}