#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

#define pii pair<int,int>
int main() {
  int a,b;
  map<int,int> m;
  map<int,int> f;
  string s;
  while(getline(cin,s)) {
    if(sscanf(s.c_str(),"%d,%d\n", &a,&b) != 2) break;
    m[a]++;
    f[a]=1;
  }
  while(scanf("%d,%d\n", &a,&b) == 2) {
    m[a]++;
    if(f[a]) f[a]=2;
  }
  vector<pii> v;
  FOR(i,m) {
    if (f[(*i).first]==2) {
      v.push_back(pii(*i));
    }
  }
  sort(ALL(v));
  FOR(i,v)
    cout << (*i).first << " " <<(*i).second << endl;
}