#include <iostream>
#include <cstdio>
#include <sstream>
using namespace std;

int company[1000001]={0};
int cc[1000001]={0};
int bb[1000001]={0};

int main(){

  string ss;
  int a,b;

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

  return 0;
}