public static void main(String[] args) {
		long start = System.currentTimeMillis();
		try {
			FileReader fr = new FileReader(SourcePath.getInputPath() + "/googleCodeJam/round1A2010/A-large-practice.in");
			FileWriter fw = new FileWriter(SourcePath.getOutputPath() + "/googleCodeJam/round1A2010/A-large-practice.out");
			
			BufferedReader br = new BufferedReader(fr);
			BufferedWriter bw = new BufferedWriter(fw);
			int numOfCases = Integer.valueOf(br.readLine());
			
			StringBuffer outPut = new StringBuffer();
			String[] caseKeys;
			int tableLength;
			int rowLength;
			String[][] table;
			String line;
			int emptySlotsNum;
			String result;
			
			for (int i = 0; i < numOfCases; i++){
				caseKeys = br.readLine().split(" ");
				
				tableLength = Integer.valueOf(caseKeys[0]);
				rowLength = Integer.valueOf(caseKeys[1]);
				
				table = new String[tableLength][tableLength];
				
				for (int length = 0; length < tableLength; length++){
					line = br.readLine();
					line = line.replace(".", "");
					
					//rotate
					emptySlotsNum = tableLength - line.length();
					for (int width = 0; width < tableLength; width++){
						table[width][length] = width < emptySlotsNum ? "." : line.substring(width - emptySlotsNum, width - emptySlotsNum + 1);
					}
					//rotate end
					
				}
				
				result = getRotateResult(table, rowLength);
				
				outPut.append("Case #").append(i+1).append(": ").append(result).append("\n");
			}

			br.close();
			fr.close();
			bw.write(outPut.toString());
			bw.flush();
			bw.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		long end = System.currentTimeMillis();
		
		System.out.println(end - start);
	}