#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int customers1[1001];
int customers2[1001];

int main() {
    int n;
    string s;
    stringstream ss;
    while(getline(cin,s)) {
        if (s =="") break;
        ss.str("");
        ss << s;
        ss >> n;
        customers1[n]++;
    }
    while(getline(cin,s)) {
        ss.str("");
        ss << s;
        ss >> n;
        customers2[n]++;
    }
    REP(i,1000) {
        if (customers1[i] && customers2[i]) {
            cout << i << " " << customers1[i]+customers2[i] << endl;
        }
    }
    return 0;
}