#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

char buf[100000];
map<int, int> table, ans;

int main() {
  while (1) {
    fgets(buf, sizeof(buf), stdin);
    int n = strlen(buf);
    if (n <= 1) break;

    int id, times;
    sscanf(buf, "%d,%d", &id, &times);
    ++table[id];
  }

  while (1) {
    if (scanf("%s", buf) != 1) break;

    int id, times;
    sscanf(buf, "%d,%d", &id, &times);
    if (ans.count(id)) ans[id]++;
    else if (table.count(id)) ans[id] = table[id] + 1;
  }

  for (auto itr=ans.begin(); itr!=ans.end(); itr++) {
    printf("%d %d\n", itr->first, itr->second);
  }
}