#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string s;
    vi d(100000,0);
    vb hoge(100000,false);
    while(getline(cin,s)){
        if(s=="")break;
        else{
            string temp;
            for(int i=0;;)if(s[i]==','){
                s.erase(s.begin()+i);
                break;
            }else {
                temp.push_back(s[i]);
                s.erase(s.begin()+i);
            }
            d[stoi(temp)]+=1;
    }
    }
    vector<pii>ans;
    while(getline(cin,s)){
            if(s=="")break;
            string temp;
        for(int i=0;;){
                if(s[i]==','){
                s.erase(s.begin()+i);
                break;
            }else{
                temp.push_back(s[i]);
                s.erase(s.begin()+i);
            }
        }
            int index=stoi(temp);
            hoge[index]=true;
            d[index]+=1;
    }
    rep(i,100000)if(d[i]&&hoge[i])cout<<i<<" "<<d[i]<<endl;
}