import std.stdio,std.string,std.conv;

int main()
{
	string s;
	bool[int] m;
	bool[int] m2;
	int[int] count;


	while((s = readln.chomp).length != 0)
	{
		string[] _s = s.split(",");
		int a = _s[0].to!int;
		m[a] = true;
		count[a]++;
	}

	while((s = readln.chomp).length != 0)
	{
		string[] _s = s.split(",");
		int a = _s[0].to!int;
		m2[a] = true;
		count[a]++;
	}

	foreach(i;0..1001)
	{
		bool* p = (i in m);
		bool* p2 = (i in m2);
		if(p && p2)
		{
			writeln(i," ",count[i]);
		}
	}

	return 0;
}