#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int cnt[1010];
bool ok[1010];

int main(void){
	string s;
	set<int> se;
	bool flag = false;
	while(getline(cin, s)){
		if(s == "") flag = true;
		cout << s << endl;
		if(!flag){
			int m = 0;
			rep(i, s.size()) if(s[i] == ','){m = i; break;}
			int c = stoi(s.substr(0, m));
			int d = stoi(s.substr(m + 1, s.size() - m));
			cnt[c]++;
			se.insert(c);
		}else{
			int m;
			rep(i, s.size()) if(s[i] == ','){m = i; break;}
			int c = stoi(s.substr(0, m));
			int d = stoi(s.substr(m + 1));
			cnt[c]++;
			if(se.count(c) != 0) ok[c] = true;
		}
	}
	rep(i, 1010) if(ok[i]) printf("%d\n", cnt[i]);
}