#include <map>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
string s; int c = 0; map<int, int> m1, m2; vector<pair<int, int> > p;
int main() {
	while(s = "", getline(cin, s)) {
	    if(s == "") c++;
	    else {
	        int t = 0;
	        for(int i = 0; i < s.size(); i++) {
	            if(s[i] == ',') break;
	            else t = t * 10 + s[i] - 48;
	        }
	        if(c == 0) m1[t]++;
	        else m2[t]++;
	    }
	}
	for(map<int, int>::iterator i = m1.begin(); i != m1.end(); i++) {
	    int t = (*i).first;
	    if(m2[t]) p.push_back(make_pair(t, m1[t] + m2[t]));
	}
	sort(p.begin(), p.end());
	for(int i = 0; i < p.size(); i++) {
	    cout << p[i].first << ' ' << p[i].second << endl;
	}
}