#include<iostream>
#include<string>
#include<cstdlib>
#include<set>
using namespace std;

int main(){
  string data;
  multiset<int> nums1,nums2;
  while(getline(cin,data,'\n')){
    if (data=="")break;
    nums1.insert(atoi(data.substr(0,data.find(",")).c_str()));
  }
  while(getline(cin,data,'\n')){
    nums2.insert(atoi(data.substr(0,data.find(",")).c_str()));
  }
  set<int>::iterator it;
  int a;
  for(it=nums1.begin();it!=nums1.end();){
    if(nums2.find(*it)!=nums2.end()){
      cout<<*it<<" "<<nums1.count(*it)+nums2.count(*it)<<endl;
    }
    a = *it;
    it++;
    while(a==*it)it++;
  }
}