#include<iostream>
#include<cstdio>
#include<algorithm>
#include<sstream>
#include<vector>
#include<cstdlib>
#include<map>
#define F first
#define S second


using namespace std;
typedef pair<int,int> P;


bool cmp(const P &p,const P &q){
  if(p.F != q.F)return p.F < q.F;
  return p.S > q.S; // iranai
}



int main(){
  string s;
  vector<P> vec;
  map<int,bool> exist;
  while(true){
    getline(cin,s,'\n');
    if(s.size() == 0)break;
    int pi;
    for(int i=0;i<s.length();i++)if(s[i] == ','){pi = i;break;}
    int A,B;
    A = (atoi)(s.substr(0,pi).c_str());
    B = (atoi)(s.substr(pi+1,s.length()-pi-1).c_str());
    vec.push_back(P(A,B));
    exist[A] = true;
  }


  vector<P> vec2;
  map<int,int> info;
  while(getline(cin,s,'\n')){
    int pi;
    for(int i=0;i<s.length();i++)if(s[i] == ','){pi = i;break;}
    int A,B;
    A = (atoi)(s.substr(0,pi).c_str());
    B = (atoi)(s.substr(pi+1,s.length()-pi-1).c_str());
    vec2.push_back(P(A,B));

    info[A]++;
  }

  

  for(int i=0;i<vec.size();i++){

  if(info[vec[i].F] > 0){

      info[vec[i].F]++;
    }
  }



  vector<P> rank;
  map<int,int>::iterator it = info.begin();
  while(it != info.end()){
    if((*it).S == 0){
      it++;
      continue;
    }

    rank.push_back(P((*it).F,(*it).S));
    it++;
  }

  sort(rank.begin(),rank.end(),cmp);
  for(int i=0;i<rank.size();i++){
    if(exist[rank[i].F])cout << rank[i].F << " " << rank[i].S << endl;
  }



  return 0;
}