#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<random>
using namespace std;
int inf = 1e9;



int main() {

  vector<int> c1(1001, 0);
  vector<int> c2(1001, 0);
  vector<int> d(1001, 0);
  int a, b;
  while( scanf("%d,%d", &a, &b) != EOF ){
    c1[a]++;
  }

  while( scanf("%d,%d", &a, &b) != EOF ){
    c2[a]++;
  }

  for(int i=0; i<1001; i++){
    if( c1[i] && c2[i] ) cout << i << " " << c1[i] + c2[i] << endl;
  }

  return 0;
}




// EOF