public static void main(String[] args) throws Exception {
		InputStream inputStream = Mirror.class.getResourceAsStream("D-small-practice.in");
		InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
		BufferedReader bf = new BufferedReader(inputStreamReader);
		int cases = Integer.parseInt(bf.readLine());
		for (int i = 0; i < cases; i++) {
			String firstLine = bf.readLine();
			int h = Integer.parseInt(firstLine.split(" ")[0]);
			StringBuilder stb = new StringBuilder();
			for (int j = 0; j < h; j++) {
				stb.append(bf.readLine());
			}
			Mirror myMirror = new Mirror(firstLine, stb.toString());
			int reflections = myMirror.calculateReflections();
			System.out.println(myMirror.toString());
			System.out.println(String.format("Case #%1$d: %2$s ", i+1, reflections));
		}
		bf.close();
		inputStreamReader.close();
		inputStream.close();
	}