Codeforces Round 783 (Div. 1)
F
Yin Yang
Codeforces
3500
原题
← E→
翻译中…

You are given a rectangular grid with $n$ rows and $m$ columns. $n$ and $m$ are divisible by $4$. Some of the cells are already colored black or white. It is guaranteed that no two colored cells share a corner or an edge.

翻译中…

Color the remaining cells in a way that both the black and the white cells becomes orthogonally connected or determine that it is impossible.

翻译中…

Consider a graph, where the black cells are the nodes. Two nodes are adjacent if the corresponding cells share an edge. If the described graph is connected, the black cells are orthogonally connected. Same for white cells.

翻译中…

Input

翻译中…

The input consists of multiple test cases. The first line of the input contains a single integer $t$ ($1 \le t \le 4000$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$, $m$ ($8 \le n, m \le 500$, $n$ and $m$ are divisible by $4$) — the number of rows and columns.

翻译中…

Each of the next $n$ lines contains $m$ characters. Each character is either 'B', 'W' or '.', representing black, white or empty cell respectively. Two colored (black or white) cell does not share a corner or an edge.

翻译中…

It is guaranteed that the sum of $n \cdot m$ over all test cases does not exceed $250\,000$.

翻译中…

Output

翻译中…

For each testcase print "NO" if there is no solution, otherwise print "YES" and a grid with the same format. If there are multiple solutions, you can print any.

翻译中…

Note

翻译中…

Solution for test case 1:

翻译中…

image

翻译中…

Test case 2: one can see that the black and the white part can't be connected in the same time. So the answer is "NO".

翻译中…

样例

Input #1
4
8 8
.W.W....
.....B.W
.W.W....
.....W.W
B.B.....
....B.B.
B.W.....
....B.B.
8 8
B.W..B.W
........
W.B..W.B
........
........
B.W..B.W
........
W.B..W.B
8 12
W.B.........
....B...B.W.
B.B.........
....B...B.B.
.B..........
........B...
.W..B.B...W.
............
16 16
.W............W.
...W..W..W.W....
.B...........B.W
....W....W......
W......B....W.W.
..W.......B.....
....W...W....B.W
.W....W....W....
...B...........W
W.....W...W..B..
..W.W...W......B
............W...
.W.B...B.B....B.
.....W.....W....
..W......W...W..
W...W..W...W...W
Output #1
YES
BWWWWWWW
BWBBBBBW
BWBWWWBW
BWBWBWBW
BWBWBWBW
BWBBBWBW
BWWWWWBW
BBBBBBBW
NO
YES
WWBBBBBBBBBB
BWWWBBBBBBWB
BBBWBBBWWWWB
BBBWBBBWBBBB
BBBWBBBWBBBB
BBBWWWWWBBBB
BWWWBBBWWWWB
BBBBBBBBBBBB
YES
WWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWW
WBBBBBBBBBBBBBWW
WBBBWBWWWWBWWBWW
WBBWWBBBWWBWWBWW
WBWWWBWWWWBWWBWW
WBBWWBBBWWBWWBWW
WWBWWWWWWWWWWWWW
WWBBBBBBBBBBBBWW
WBBBWWWBWWWBWBWW
WWWBWBBBWBBBWBBB
WWWBWBWWWWWBWWBW
WWWBWBBBWBBBWWBW
WWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWW
WWWWWWWWWWWWWWWW
InputCopy OutputCopy
题目信息
题号
1667F
时间限制
3 s
内存限制
256 MB
标签
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。