 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 
 using namespace std;
 
 int main()
 {
   int arr[1005]={0};
   int arr2[1005]={0};
   map<int,int> mm;
   map<int,int>::iterator iter;
   string s;
   bool change=false;
   while(getline(cin,s))
   {
     //if(s=="0")  break;
     int num,d;
     char temp;
     if(s=="")
     {
       change=true;
       continue;
     }
     if(!change)
     {
       cin>>num>>temp>>d;
       mm[num]++;    
       arr[num]=1;     
     }
     else
     {
       cin>>num>>temp>>d;
       mm[num]++;    
       arr2[num]=1;   
     }     
   }
   for(iter=mm.begin();iter!=mm.end();++iter)
     {
       if(arr[iter->first]&&arr2[iter->first])
       {
         cout<<iter->first<<" "<<iter->second<<endl;                                       
       }                                          
     } 
   //while(1);
   return 0;
 }

 
  