#include <cstdio>
#include <cstring>

#define N 1000

using namespace std;

int main(void){
  int c0[N+1]={0}, c1[N+1]={0};
  int c,d;
  char buf[16];
  
  while (fgets(buf, 16, stdin), strlen(buf)>2){
    sscanf(buf, "%d,%d", &c,&d);
    c0[c]++;
  }
  while (fgets(buf, 16, stdin)){
    sscanf(buf, "%d,%d", &c,&d);
    c1[c]++;
  }
  for (int i=1; i<=N; i++){
    if (c0[i]>0 && c1[i]>0){
      printf("%d %d\n",i, c0[i]+c1[i]);
    }
  }
  
  return 0;
}
