#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int main() {
  int sum=0,i,name,count;
  string s;
  map<int,int> a,b;
  map<int,int>::iterator it,it2;
  
  while(1) {
    getline(cin, s);
    if(s=="") break;
    i=0;
    name=0;
    while(1) {
      if(s[i]==',') break;
      name*=10;
      name+=(int)s[i]-48;
      i++;
    }
    it=a.find(name);
    if(it==a.end()){
      a.insert(make_pair(name,1));
    } else {
      count=it->second;
      a.erase(it);
      a.insert(make_pair(name,count+1));
    }
  }
  while(scanf("%d%*c%*d",&name)==1) {
    it=b.find(name);
    if(it==b.end()){
      b.insert(make_pair(name,1));
    } else {
      count=it->second;
      b.erase(it);
      b.insert(make_pair(name,count+1));
    }
  }

  for(it=b.begin(); it!=b.end(); it++) {
    it2=a.find(it->first);
    if(it2!=a.end()) cout << it->first << " " << it->second+it2->second << endl;
  }
  return 0;
}
