#include <iostream>
#include <string>
#include <sstream>
#include <map>
#include <algorithm>
using namespace std;

int main(){
  int c,t,i=0,l[1001]={0};
  map<int,bool> m;
  string s;
  char cm;
  while(getline(cin,s)&&s.size()>0){
    stringstream ss(s);
    ss>>c>>cm>>t;
    l[c]++;
  }
  while(getline(cin,s)){
    stringstream ss(s);
    ss>>c>>cm>>t;
    if(l[c]>0){
      m[c]=true;l[c]++;
    }
  }
  for(map<int,bool>::iterator it=m.begin();it!=m.end();++it){
    cout<<it->first<<" "<<l[it->first]<<endl;
  }
  return 0;
}