#include<iostream>
#include<map>
using namespace std;
int main(){
  map<int,int> pr,th;
  string s;
  bool f = true;
  while(getline(cin,s)){
    if(s.find(',') == string::npos){f = false; continue;}
    int a = 0;
    for(int i=0; s[i]!=','; i++) if(s[i]>='0' && s[i]<='9') a = a*10+s[i]-'0';
    if(f) pr[a]++;
    else if(th[a]!=0) th[a]++;
    else if(pr[a]!=0) th[a] = pr[a]+1;
  }
  for(map<int,int>::iterator it = th.begin(); it!=th.end(); it++)
    cout <<(it->first)<<" "<<(it->second)<<endl;
  return 0;
}