#include <iostream>
#include <string>
#include <cstring>
#include <sstream>

using namespace std;

int main() {

  int a = 0;
  int res[2000][2] = {};

  while (true) {
    string s;
    if (!getline(cin, s))
      break;

    if (s == "") {
      a = 1;
      continue;
    }

    int c, d;
    string s2;
    stringstream ss(s);
    getline(ss, s2, ',');
    res[atoi(s2.c_str())][a] += 1;
  }

  for (int i = 0; i < 2000; ++i)
    if ( (res[i][0] != 0) && (res[i][1] != 0) )
      cout << i << " " << res[i][0] + res[i][1] << endl;
}
