#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<climits>
#include<cmath>
#include<map>

#define f first
#define s second
#define mp make_pair

#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()

typedef unsigned int uint;
typedef long long ll;

using namespace std;

int main(){
  string str;
  map<int,pair<int,int> > m;
  while(getline(cin,str), str != ""){
    int a,b;
    sscanf(str.c_str(),"%d,%d",&a,&b);
    m[a].f |= 1;
    m[a].s++;
  }
  while(getline(cin,str) && str != ""){
    int a,b;
    sscanf(str.c_str(),"%d,%d",&a,&b);
    m[a].f |= 2;
    m[a].s++;
  }
  FOR(it,m)
    if(it->s.f == 3)
      cout << it->f << " " << it->s.s << endl;
  return 0;
}