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

int main(){
  string s;
  map<int, int> trade1, trade2;
  while(getline(cin, s)){
    if(s.size() == 0) break;
    replace(s.begin(), s.end(), ',', ' ');
    istringstream is(s);
    int t;
    is >> t;
    trade1[t]++;
  }

  while(getline(cin, s)){
    if(s.size() == 0) break;
    replace(s.begin(), s.end(), ',', ' ');
    istringstream is(s);
    int t;
    is >> t;
    trade2[t]++;
  }
  for(map<int, int>::iterator it = trade1.begin() ; it != trade1.end() ; it++){
    map<int, int>::iterator f = trade2.find(it->first);
    if(f != trade2.end()){
      cout << it->first << ' ' << it->second + trade2[it->first] << endl;
    }
  }
  return 0;
}

  