#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a[1001],b[1001],c,d;
  char tmp[100];
  for(int i=0;i<1001;i++){
    a[i]=0;b[i]=0;
  }
  while(strcmp(fgets(tmp,99,stdin),"\n")!=0){
    sscanf(tmp,"%d,%d",&c,&d);
    a[c]++;
  }
  while(scanf("%d,%d",&c,&d)!=EOF){
    b[c]++;
  }
  for(int i=1;i<1001;i++){
    if(a[i]>0 && b[i]>0){
      printf("%d %d\n",i,a[i] + b[i]);
    }
  }
}