#include <iostream>
#include <cstdio>
#include <sstream>
using namespace std;
int main(){

  string ss;
  int a,b;
  int company[1001]={0};

  while(getline(cin,ss)&&ss.size() > 0){
    sscanf(ss.c_str(),"%d,%d",&a,&b);
    company[a]++;  
  }
  while(getline(cin,ss)&&ss.size() > 0){
    sscanf(ss.c_str(),"%d,%d",&a,&b);
    company[a]++;  
  }
  for(int i = 0 ; i <= 1000 ; i++){
    if(company[i] >= 2)cout << i << " " << company[i] << endl;
  }

  return 0;
}