#include<iostream>
#include<map>
#include<vector>
#include<algorithm>

using namespace std;

const int MAX = 1001;

typedef struct{
  int sum;
  int flg;
}Info;

Info data[MAX];
string in;
int name,day;
char trash;
vector<int> V;
map <int,int> M;

void convert(string str){
  int i = 0,rev = 1;
  name = day = 0;
  reverse(str.begin(),str.end());
  str += "\n";
  while(1){
    if(str[i] >= '0' && str[i] <= '9') day += (str[i]-'0')*rev;
    else break;
    rev *= 10;
    i++;
  }
  rev = 1;
  while(1){
    i++;
    if(str[i] >= '0' && str[i] <= '9') name += (str[i]-'0')*rev;
    else break;
    rev *= 10;
  }
}

int main(){

  while(getline(cin,in)){
    if(in == "")break;
    convert(in);
    data[name].flg = 1;
    data[name].sum++;
  }
  
  while(getline(cin,in)){
    convert(in);
    if(data[name].flg) data[name].flg = 2;
    data[name].sum++;
  }

  for(int i = 0; i < MAX; i++){
    if(data[i].flg == 2) cout << i << " " << data[i].sum << endl;
  }
  return 0;
}