#include <iostream>
#include <sstream>
#include <bitset>
#include <string>
#include <vector>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cctype>
#include <numeric>
#include <cassert>

using namespace std;

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){
    os << "{ ";
    for (typename vector<T>::const_iterator it = v.begin(); it != v.end(); ++it)
        os << *it << (it + 1 == v.end() ? "" : ", ");
    os << " }";
    return os;
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long ul;
typedef unsigned long long ull;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair

int main(void){
    vb lastmonth(1000);
    vb thismonth(1000);
    map<int, int> t;
    int num, val;
    string str;

    while (getline(cin, str), str.size() != 0){
        istringstream iss(str);
        iss >> num;
        iss.ignore();
        iss >> val;
        lastmonth[num] = true;
        t[num]++;
    }

    while (getline(cin, str)){
        istringstream iss(str);
        iss >> num;
        iss.ignore();
        iss >> val;
        thismonth[num] = true;
        t[num]++;
    }

    for (auto const& it : t){
        if (lastmonth[it.first] && thismonth[it.first]){
            cout << it.first << " " << it.second << endl;
        }
    }
}