public static void main(String[] args) throws Exception{
		
		Scanner In = new Scanner(new File("d:\\programDATA\\Watersheds\\B-small-practice.in"));
		System.setOut(new PrintStream(new File("d:\\programDATA\\Watersheds\\small-output1.out")));
		
		int numCases = In.nextInt();
		
		for(int currCase = 1;currCase <= numCases;currCase++){
			
			H = In.nextInt(); W = In.nextInt();
			alt = new int[H][W];
			grid = new char[H][W];
			currBas = -1;
			
			for(int i = 0;i < H;i++)
				for(int j = 0;j < W;j++)
					alt[i][j] = In.nextInt();
			
			for(int i = 0;i < H;i++) Arrays.fill(grid[i], ' ');
			
			
			for(int i = 0;i < H;i++)
				for(int j = 0;j < W;j++)
					if(grid[i][j] == ' ')
						traverse(i, j);
			
			System.out.println("Case #"+currCase+":");
			for(int i = 0;i < H;i++){
				for(int j = 0;j < W;j++)
					System.out.print(grid[i][j]+" ");
				System.out.println();
			}
			
		}
	}