#include<stdio.h>
#include<list>
#include<string.h>
#include<stdlib.h>
class tr{
 public:
  int num;
  int count;
  int flg;
  tr(int n){
    num=n;
    count=1;
    flg=0;
  }
};

int main(){
  int num,c;
  using namespace std;
  char hoge[1000],*ca;
  list<tr> t1;
  list<tr>::iterator it;
  do{
    fgets(hoge,1000,stdin);
    if(!strcmp(hoge,"\n")) break;
    ca=strchr(hoge,',');
    *ca='\0'; ca++;
    num=atoi(hoge);
    c=atoi(ca);
    it=t1.begin();
    while(it!=t1.end()){
      if(it->num==num){
	it->count++;
	break;
      }
      it++;
    }
    if(it==t1.end()){
      it=t1.begin();
      while(it!=t1.end()){
	if(it->num>num) break;
	it++;
      }
      t1.insert(it,*(new tr(num)));
    }
  }while(1);
  it=t1.begin();
  while(it!=t1.begin()){
    printf("%d %d\n",it->num,it->count);
  }
  do{
    if(!fgets(hoge,1000,stdin)) break;
    ca=strchr(hoge,',');
    *ca='\0'; ca++;
    num=atoi(hoge);
    c=atoi(ca);
    it=t1.begin();
    while(it!=t1.end()){
      if(it->num==num){
	it->count++;
	it->flg=1;
	break;
      }
      it++;
    }
  }while(1);
  it=t1.begin();
  while(it!=t1.end()){
    if(it->flg) printf("%d %d\n",it->num,it->count);
    it++;
  }
  return 0;
}