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

int main(void){
    string s;
    int a[3][1010];
    while(getline(cin, s), s!=""){
        int c, d;
        stringstream ss(s);
        ss>>c>>d;
        a[0][c]++;
    }
    while(getline(cin, s), s!=""){
        int c, d;
        stringstream ss(s);
        ss>>c>>d;
        a[1][c]++;
    }
    for(int i=1; i<1001; i++){
        if(a[0][i]>0 && a[1][i]>0){
            cout << i << " " << a[0][i]+a[1][i];
        }
    }
}

