#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define ite ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
string itos(int a){
  string out;
  if(a==0)out="0";
  while(a){
    out=(char)(a%10+'0')+out;
    a/=10;
  }
  return out;
}
int main(){
  vector<int>v;
  map<string,int>m1,m2;
  string s;
  while(getline(cin,s),s!=""){
    long long int a[2]={0};
    string b;
    int i=0;
    while(s[i]!=','){a[0]*=10;a[0]+=s[i]-'0';i++;}
    b=itos(a[0]);
    //i++;
    //while(i!=s.size()){a[1]*=10;a[1]+=s[i]-'0';i++;}
    m1[b]++;
    v.pb(a[0]);
  }
  while(cin>>s){
    long long int a[2]={0};
    int i=0;
    string b;
    while(s[i]!=','){a[0]*=10;a[0]+=s[i]-'0';i++;}
    b=itos(a[0]);
    //i++;
    //while(i!=s.size()){a[1]*=10;a[1]+=s[i]-'0';i++;}
    m2[b]++;
  }
  sort(all(v));
  int i=0,c=-1;
  rep(i,v.size()){
    string tmp=itos(v[i]);
    if(c==v[i])continue;
    else c=v[i];
  //for(map<string,int>ite it=m1.begin();it!=m1.end();it++){
    //cout<<"!"<<endl;
    //if(m2[it->first]!=0)cout<<it->first<<" "<<it->second+m2[it->first]<<endl;
    if(m2[tmp]!=0)cout<<v[i]<<" "<<m1[tmp]+m2[tmp]<<endl;
  }
}