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

map<int, int, less<int> > baka;
int used[100000];

int main() {
  stringstream ss;
  int aho, doji;
  char ch;

  while(1){
    string str;
    getline(cin, str);
    if(str == "") break;
    stringstream ss(str);
    ss >> aho >> ch >> doji;
    baka[aho] ++;
    used[aho] ++;
  }
  
  while(1){
    string str;
    if(!getline(cin, str)) break;
    stringstream ss(str);
    ss >> aho >> ch >> doji;
    if(!used[aho]) continue;
    baka[aho] ++;
  }
  
  for(map<int, int>::iterator it = baka.begin(); it!=baka.end(); it++) {
    if(it->second<=1) continue;
    
    cout << it->first << " " << it->second << endl;
  }
  
  return 0;
}