#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
 
int main() {
    int s1[1010][32];
    int s2[1010][32];
    string s;
    rep(i,0,1010) {
        memset(s1 + i, 0, sizeof(s1[i]));
        memset(s2 + i, 0, sizeof(s2[i]));
    }

    int a,b;
    while(getline(cin,s)) {
        if(s.empty()) break;
        sscanf(s.c_str(),"%d,%d",&a,&b);
        s1[a][b]++;
    }

    while(getline(cin,s)) {
        sscanf(s.c_str(),"%d,%d",&a,&b);
        s2[a][b]++;
    }

    rep(i,0,1010) {
        int x = 0, y = 0;
        rep(j,0,32) {
            if(s1[i][j] != 0) x++;
            if(s2[i][j] != 0) y++;
        }
        if(x != 0 && y != 0) {
            printf("%d %d\n",i,x+y);
        }
    }
    return 0;
}