#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

struct DATA{
  int Number;
  int Count;
};

void Device(string, int&, int&);
int Atoi(const string);
void PushData(vector<DATA>&, int);
bool Compare(const DATA&, const DATA&);

int main(){
  int i, j, number, day;
  string str;
  DATA _Answer;
  vector<DATA> ThisMonth, LastMonth, Answer;

  while(1){
    getline(cin, str);
    if(str == "") break;
    Device(str, number, day);
    PushData(ThisMonth, number);
  }

  sort(ThisMonth.begin(), ThisMonth.end(), Compare);

  while(cin >> str){
    Device(str, number, day);
    PushData(LastMonth, number);
  }

  sort(LastMonth.begin(), LastMonth.end(), Compare);

  for(i=0; i<ThisMonth.size(); ++i){
    for(j=0; j<LastMonth.size(); ++j){
      if(ThisMonth[i].Number == LastMonth[j].Number){
	_Answer.Number = ThisMonth[i].Number;
	_Answer.Count = ThisMonth[i].Count + LastMonth[j].Count;
	Answer.push_back(_Answer);
	break;
      }else if(ThisMonth[i].Number < LastMonth[j].Number){
	break;
      }
    }
  }

  for(i=0; i<Answer.size(); ++i)
    cout << Answer[i].Number << " " << Answer[i].Count << endl;

  return 0;
}

void Device(string s, int& x, int& y){
  string s1, s2;
  string::iterator iter;

  iter = find(s.begin(), s.end(), ',');
  copy(s.begin(), iter, back_inserter(s1));
  copy(iter+1, s.end(), back_inserter(s2));

  x = Atoi(s1);
  y = Atoi(s2);
}

int Atoi(const string s){
  int i, x=0, digit=1;

  for(i = s.size()-1; i >= 0; --i){
    x = x + (s[i] - 48) * digit;
    digit *= 10;
  }
  return x;
}

void PushData(vector<DATA>& month, int x){
  int i, isFound=0;
  DATA data;

  for(i=0; i<month.size(); ++i){
    if(x == month[i].Number){
      isFound = 1;
      ++month[i].Count;
      break;
    }
  }

  if(isFound == 0){
    data.Number = x;
    data.Count = 1;
    month.push_back(data);
  }
}

bool Compare(const DATA& x, const DATA& y){
  return x.Number < y.Number;
}