#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <algorithm>
using namespace std;
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  string s;
  int corp, date;
  char c;
  map<int, int> m;
  while (getline(cin, s)) {
    if (sz(s) == 0)
      break;
    istringstream is(s);
    is >> corp >> c >> date;
    m[corp]++;
  }
  while (cin >> corp >> c >> date) {
    if (m[corp])
      m[corp]++;
  }
  for (auto& p : m) {
    if (p.second > 1)
      cout << p.first << " " << p.second << endl;
  }
  return 0;
}