#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
#define print(Target) cout << Target << '\n'
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;

bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

struct PRO{
  int num;
  int cnt;
};

bool cmp(PRO lhs, PRO rhs)
{
  return (lhs.num < rhs.num);
}

signed main()
{
  ios::sync_with_stdio(false);
  vector<PRO> pro;
  string s;

  while (getline(cin, s), !s.empty()){
    stringstream ss(s);
    int num, day;
    char c;
    ss >> num >> c >> day;
    bool first = true;
    REP(i, pro.size()){
      if (pro[i].num == num){
        pro[i].cnt++;
        first = false;
      }
    }
    if (first){
      pro.pb((PRO){num, 1});
    }
  }

  while (getline(cin, s), !s.empty()){
    stringstream ss(s);
    int num, day;
    char c;
    ss >> num >> c >> day;
    bool first = true;
    REP(i, pro.size()){
      if (pro[i].num == num){
        pro[i].cnt++;
        first = false;
      }
    }
    if (first){
      pro.pb((PRO){num, 1});
    }
  }

  sort(pro.begin(), pro.end(), cmp);
  REP(i, pro.size()){
    if (pro[i].cnt >= 2){
      cout << pro[i].num << " " << pro[i].cnt << '\n';
    }
  }

  return (0);
}