#include<iostream>
#include<map>
#include<cstdio>
using namespace std;
int main(){
  map<int,int> pr,th;
  string s;
  bool f = true;
  int a;
  while(getline(cin,s)){
    if(s.find(',') == string::npos){f = false; continue;}
    sscanf(s.c_str(),"%d,%*d",&a);
    if(f) pr[a]++;
    else if(th[a]!=0) th[a]++;
    else if(pr[a]!=0) th[a] = pr[a]+1;
  }
  for(map<int,int>::iterator it = th.begin(); it!=th.end(); it++)
    if(it->second!=0)
      cout <<(it->first)<<" "<<(it->second)<<endl;
  return 0;
}