#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <set>
#include <map>
using namespace std;

int main() {
  string s;
  map<int,pair<int,int> > m;
  int k = (1<<0);
  while(getline(cin, s)) {
    if(s == "") {
      k = (k<<1);
    } else {
      stringstream ss(s);
      int id;
      ss >> id;
      ++m[id].first;
      m[id].second |= k;
    }
  }

  for(map<int,pair<int,int> >::iterator it = m.begin();
      it != m.end(); ++it) {
    if(it->second.second == 3) {
      cout << it->first << " " << it->second.first << endl;
    }
  }
  return 0;
}