#include <iostream>
#include <cstdlib>
using namespace std;

int main() {
  int cust,to,lastmonth[1001] = {0},thismonth[1001] = {0};
  string s;
  while(getline(cin,s)) {
    to = s.find(",");
    if(atoi(s.substr(0,to).c_str()) == 0) break;
    lastmonth[atoi(s.substr(0,to).c_str())]++;
  }
  while(getline(cin,s)) {
    to = s.find(",");
    thismonth[atoi(s.substr(0,to).c_str())]++;
  }
  for(int i=0;i<1001;i++) {
    if((thismonth[i] >= 1) && (lastmonth[i] >= 1)) {
      cout << i << " " << lastmonth[i] + thismonth[i] << endl;
    }
  }

}