#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
using namespace std;

vector<string> split(const string &str, char delim){
  vector<string> res;
  size_t current = 0, found;
  while((found = str.find_first_of(delim, current)) != string::npos){
    res.push_back(string(str, current, found - current));
    current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}


int main()
{
	string s;
	map<int,bool> m;
	map<int,bool> m2;
	map<int,int> count;

	while(getline(cin,s) && s.size())
	{
		vector<string> _s = split(s,',');
		int a = atoi(_s[0].c_str());
		m[a] = true;
		count[a]++;
	}

	while(getline(cin,s))
	{
		vector<string> _s = split(s,',');
		int a = atoi(_s[0].c_str());
		m2[a] = true;
		count[a]++;
	}

	for(int i=0;i<1001;i++)
	{
		if(m2.find(i) != m2.end() && m.find(i) != m.end())
		{
			cout << i << " " << count[i] << endl; 
		}
	}
	return 0;
}