#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

struct Pair{ Pair(int k, int p) : key(k), point(p) {} int key, point; };
bool operator == (Pair l, Pair r)
{   return l.key == r.key;  }
bool operator < (Pair l, Pair r)
{   return l.key < r.key;   }

vector<string> split(string str, string delim)
{
    vector<string> result;
    int cutAt;
    while( (cutAt = str.find_first_of(delim)) != str.npos )
    {
        if(cutAt > 0)
        {
            result.push_back(str.substr(0, cutAt));
        }
        str = str.substr(cutAt + 1);
    }
    if(str.length() > 0)
    {
        result.push_back(str);
    }
	return result;
}

const int C = 10000;
int main()
{
    vector<Pair> p;
    string buf;
    
    while(getline(cin, buf))
    {
        if(buf.empty()) break;
        vector<string> v = split(buf, ",");
        
        bool f = true;
        rep(i, p.size()) if(p[i].key == atoi(v[0].c_str()))
        {
            p[i].point++;
            f = false;
            break;
        }
        if(f) p.push_back(Pair(atoi(v[0].c_str()), 1));
    }
    
    sort(ALL(p));
    
    while(cin >> buf)
    {
        vector<string> v = split(buf, ",");
        rep(i, p.size()) if(p[i].key == atoi(v[0].c_str()))
        {
            if(p[i].point > 0) p[i].point -= C;
            p[i].point++;
        }
    }
    
    rep(i, p.size()) if(p[i].point < 0)
    {
        cout << p[i].key << " " << p[i].point + C << endl;
    }
}