#P9878. [EC Final 2021] Check Pattern is Bad

    ID: 11136 远端评测题 10000ms 1024MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>2021Special JudgeO2优化构造ICPC

[EC Final 2021] Check Pattern is Bad

Problem Description

Prof. Pang is given an n×mn\times m board. Some cells are colored black, some cells are colored white, and others are uncolored.

Prof. Pang doesn't like check patterns\textbf{check patterns}, so he wants to color all uncolored cells such that there is no check pattern on the board.

44 cells forming a 2×22\times 2 square are said to have the check pattern if they are colored in one of the following ways:

BW
WB
WB
BW

Here W ("wakuda" in Chewa language) means the cell is colored black and B ("biancu" in Corsican language) means the cell is colored white.

Input Format

The first line contains a single integer TT (1≤T≤104)(1\leq T \leq 10^4) denoting the number of test cases.

The first line of each test case contains two integers nn and mm (1≤n,m≤1001\le n, m\le 100) denoting the dimensions of the board.

Each of the next nn lines contains mm characters. The jj-th character of the ii-th line represents the status of the cell on the ii-th row and jj-th column of the board. The character is W if the cell is colored black, B if the cell is colored white, and ? if the cell is uncolored.

It is guaranteed that the sum of nmnm over all test cases is no more than 10610^6.

Output Format

For each test case, output a line containing NO\texttt{NO} if you cannot color all the uncolored cells such that there is no check pattern on the board.

Otherwise, output a line containing YES\texttt{YES}. In the next nn lines, output the colored board in the same format as the input. The output board should satisfy the following conditions.

  • It does not have any check pattern.
  • It consists of only B\texttt{B} and W\texttt{W}.
  • If a cell is already colored in the input, its color cannot be changed in the output.

If there are multiple solutions, output any of them.

3
2 2
??
??
3 3
BW?
W?B
?BW
3 3
BW?
W?W
?W?
YES
BW
WW
NO
YES
BWB
WWW
BWB