import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	int[int] cnt;
	int[int] flag;
	bool f;
	foreach (line; stdin.byLine) {
		if (!line.length) {
			f = 1;
			continue;
		}
		auto key = line.split(",").map!(to!int)[0];
		cnt[key]++;
		if (!f) {
			flag[key] = 1;
		} else if (flag.get(key, 0)) {
			flag[key] = 2;
		} else {
			flag[key] = 0;
		}
	}
	foreach (key; cnt.keys.sort) {
		if (cnt[key] < 2 || flag[key] != 2) continue;
		writeln(key, " ", cnt[key]);
	}
}