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

map<int,int> m;
map<int,int> v;

int main() {
  string line;
  int p = 0;
  while(getline(cin, line)) {
    if(line.size() == 0) {
      p = 1;
      continue;
    }
    replace(line.begin(), line.end(), ',', ' ');
    stringstream ss;
    ss << line;
    int a;
    ss >> a;
    ++m[a];
    v[a] |= (1<<p);
  }
  for(map<int,int>::iterator it = m.begin(); it != m.end(); ++it) {
    if(v[it->first] == (1<<2)-1)
      cout << it->first << " " << it->second << endl;
  }
  return 0;
}