#include <iostream>
#include <map>
#include <sstream>

int main(){
  std::map<int, int> m;
  std::string s;
  int num, sales,t;
  while(std::getline(std::cin, s), s.size()){
    std::stringstream ss;
    char c;
    ss << s;
    ss >> num >> c >> sales;
    m[num] = -(-m[num]+1);
  }
  while(std::getline(std::cin, s), s.size()){
    std::stringstream ss;
    char c;
    ss << s;
    ss >> num >> c >> sales;
    if(m[num] >= 0)
      m[num]++;
    else
      m[num] = -(-m[num]+1);
  }
  std::map<int, int>::iterator it = m.begin();
  while(it != m.end()){
    if((*it).second < -1)
      std::cout << (*it).first << " " << -(*it).second << std::endl;
    it++;
  }
}