#include <iostream>
#include <map>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(void){
  map<int,int> s1,s2;
  string s;
  while(getline(cin,s),s!=""){
    int num,date;
    sscanf(s.c_str(),"%d,%d",&num,&date);
    if(s1.find(num)!=s1.end()) ++s1[num];
    else s1[num]=1;
  }
  while(getline(cin,s)){
    int num,date;
    sscanf(s.c_str(),"%d,%d",&num,&date);
    if(s2.find(num)!=s2.end()) ++s2[num];
    else s2[num]=1;
  }
  for(map<int,int>::iterator it=s1.begin();it!=s1.end();++it){
    if(s2.find(it->first)!=s2.end())cout<<(it->first)<<" "<<(it->second+s2.find(it->first)->second)<<endl;
  }
  
  return 0;
}