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