#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define inf (1e9)
#define eps (1e-9)

int main() {
  set<int> a;
  map<int, int> b;
  set<int> c;
  string s;
  int ans = 0;
  bool pre = true;
  while (getline(cin, s)) {
    if (s == "") {
      pre = false;
      continue;
    }
    stringstream ss(s);
    int x; ss >> x;
    if (pre) {
      a.insert(x);
    } else {
      if (a.count(x) > 0) c.insert(x);
    }
    b[x]++;
  }
  for (int x: c) {
    cout << x << ' ' << b[x] << endl;
  }

  return 0;
}