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

map<int, int> m1, m2;

int main(){
  string s;
  while(getline(cin, s)){
    string n;
    if(s=="")break;
    stringstream ss(s);
    getline(ss, n, ',');
    istringstream is(n);
    int key;
    is>>key;
    if(m1.find(key)!=m1.end())m1[key]++;
    else m1.insert(map<int, int>::value_type(key, 1));
  }
  while(getline(cin, s)){
    string n;
    stringstream ss(s);
    getline(ss, n, ',');
    istringstream is(n);
    int key;
    is>>key;
    if(m2.find(key)!=m2.end())m2[key]++;
    else m2.insert(map<int, int>::value_type(key, 1));
  }
  for(map<int, int>::iterator it=m1.begin(); it!=m1.end(); it++){
    if(m2.find(it->first)!=m2.end()){
      cout<<it->first<<' '<<m1[it->first]+m2[it->first]<<endl;
    }
  }
  return 0;
}