#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<string> split(const string &s, const char& sep) {
  vector<string> res;
  stringstream ss(s);
  string buffer;
  while (getline(ss, buffer, sep)) res.emplace_back(buffer);
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  int prev[1010] = {}, next[1010] = {};
  bool flag = false;
  while (getline(cin, s)) {
    if (s.find(',') == string::npos) flag = true;
    else {
      auto v = split(s, ',');
      int id = stoi(v[0]);
      if (flag) next[id] += (prev[id] > 0);
      else prev[id]++;
    }
  }
  for (int i = 1; i <= 1000; i++) {
    if (prev[i] && next[i]) cout << i << " " << prev[i] + next[i] << endl;
  }

  return 0;
}
