#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
vector<int> in;
map<int,int> m;
vector<int> v;
int main(void){
  int a,b,n=0;
  char s[256];
  bool f = true;
  while(fgets(s,sizeof(s),stdin) != NULL){
    if(s[0] == '\n'){
      f = false;
      continue;
    }
    sscanf(s,"%d,%d",&a,&b);
    in.push_back(a);
    if(f) n++;
  }

  for(int i = 0; i < n; i++){
    m[in[i]]++;
  }

  for(int i = n; i < (int)in.size(); i++){
    if(m.find(in[i]) != m.end()){
      v.push_back(in[i]);
      m[in[i]]++;
    }
  }

  sort(v.begin(),v.end());
  v.erase( unique(v.begin(),v.end()), v.end());

  for(int i = 0; i < (int)v.size(); i++){
    printf("%d %d\n",v[i],m[v[i]]);
  }
}