public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(new File("d:\\programDATA\\Watersheds\\B-small-practice.in"));
		System.setOut(new PrintStream(new File("d:\\programDATA\\Watersheds\\B-small-practice.out")));
		int T = in.nextInt();
		for (int cur = 0; cur < T; cur++) {
			H = in.nextInt(); W = in.nextInt();
			input = new int[H][W];
			result = new char[H][W];
			curBase = -1;
			
			/*初始化输入数组*/
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					input[i][j] = in.nextInt();
				}
			}
			/*初始化结果数组*/
			for (int i = 0; i < H; i++) Arrays.fill(result[i], ' ');
			
			for (int i = 0; i < H; i++) 
				for (int j = 0; j < W; j++) 
					if(result[i][j] == ' ')
						calc(i,j);

			
			System.out.println("Case #"+(cur+1)+":");
			
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					System.out.print(result[i][j]+" ");
				}
				System.out.println();
			}
		}
	}