#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    int i = 0, number;
    int trade1[1000] = {0}, trade2[1000] = {0};
    string input;

    while(getline(cin, input), !input.empty())
        trade1[atoi(input.c_str())]++;
    while(getline(cin, input), !input.empty())
        trade2[atoi(input.c_str())]++;
    rep(i,1000)
        if(trade1[i] != 0 && trade2[i] != 0)
            cout << i << ' ' << trade1[i] + trade2[i] << endl;
}