#include<iostream>
#include<sstream>
#include<string>
#include<map>
#include<cstdlib>
using namespace std;
int main(){
  int a,b;
  char c;
  string s;
  map<int,int> m;
  map<int,int>::iterator it;
  while(getline(cin,s),s.size()){
    stringstream ss(s);
    ss>>a>>c>>b;
    m[a]--;
  }
  while(getline(cin,s)){
    stringstream ss(s);
    ss>>a>>c>>b;
    if(m.count(a))m[a]=abs(m[a])+1;
  }
  for(it=m.begin();it!=m.end();it++){
    if(it->second>0)cout<<it->first<<" "<<it->second<<endl;
  }
}