#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
#define F first
#define S second
vector<int> K[2];
vector<P> T[2];
int main(){
  char buf[256];
  int k,t;
  while(1){
    fgets(buf,sizeof(buf),stdin);
    if(buf[0]=='\n') break;
    sscanf(buf,"%d,%d",&k,&t);
    K[0].push_back(k);
  }
  while(~scanf("%d,%d",&k,&t)){
    K[1].push_back(k);
  }
  for(int i=0;i<2;i++){
    sort(K[i].begin(),K[i].end());
    int tmp = K[i][0]-1;
    for(int j=0;j<(int)K[i].size();j++){
      if(tmp != K[i][j]){
	tmp = K[i][j];
	T[i].push_back(P(tmp,1));
      }
      else{
	T[i].back().S++;
      }
    }
  }
  for(int i=0,j=0;i<(int)T[0].size() && j<(int)T[1].size();){
    if(T[0][i].F==T[1][j].F){
      printf("%d %d\n",T[0][i].F,T[0][i].S+T[1][j].S);
      i++; j++;
    } else if (T[0][i].F < T[1][j].F){
      i++;
    } else {
      j++;
    }
  }
}