#include <iostream>
#include <map>
#include <cstdlib>
using namespace std;

int main() {
  string str;
  char *e;
  const char *p1, *p2;
  int a;
  map<int, int> mp;
  
  while(getline(cin, str)) {
    if(str=="") break;
    p1 = &str[0];
    a = strtol( p1, &e, 10 );
    mp[a] ++;
  }
  
  while(getline(cin, str)) {
    p2 = &str[0];
    a = strtol( p2, &e, 10 );
    mp[a] ++;
  }

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