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

int main(){
  map<int,int> cnt;
  map<int,int> flg;
  char str[128];
  set<int> num1;
  set<int> num2;
  while(gets(str)){
    if(str[0] == '\0') break;
    int idx = 0;
    int tmp = 0;
    while(str[idx] != ','){
      tmp *= 10;
      tmp += str[idx] - '0';
      idx++;
    }
    num1.insert(tmp);
    cnt[tmp]++;
  }
  string s;
  while(cin >> s){
    int idx = 0;
    int tmp = 0;
    while(s[idx] != ','){
      tmp *= 10;
      tmp += s[idx] - '0';
      idx++;
    }
    num2.insert(tmp);
    cnt[tmp]++;
  }
  for(set<int>::iterator itr = num1.begin();itr != num1.end();++itr) flg[*itr]++;
  for(set<int>::iterator itr = num2.begin();itr != num2.end();++itr) {
    if(flg[*itr] == 1){
      cout << *itr << " " << cnt[*itr] << endl;
    }
  }
}