#include <bits/stdc++.h>
using namespace std;

pair<int, int> perse(string s) {
  int a = 0, b = 0;
  int i = 0;
  while (s[i] != ',') {
    int x = s[i] - '0';
    a = 10 * a + x;
    ++i;
  }
  // cerr << a << " ";
  ++i;
  while (i != s.size()) {
    int x = s[i] - '0';
    b = 10 * b + x;
    ++i;
  }
  // cerr << b << endl;

  return make_pair(a, b);
}

int main() {
  string s;
  int cnt[2][1001] = {};

  int idx = 0;
  while (getline(cin, s)) {
    if (s == "") {
      idx++;
      continue;
    }

    pair<int, int> data = perse(s);
    cnt[idx][data.first]++;

    // cerr << data.first << " " << data.second << endl;
  }
  for (int i = 1; i <= 1000; ++i) {
    if (cnt[0][i] && cnt[1][i]) cout << i << " " << cnt[0][i] + cnt[1][i] << endl;
  }
}