#include <iostream>
#include <cstdio>
#include <queue>
#define mk make_pair
using namespace std;
int n, m; char a[105][105];
bool check(int x, int y)
{
if (a[x][y] == 'B' && a[x + 1][y] == 'W' && a[x][y + 1] == 'W' && a[x + 1][y + 1] == 'B') return false;
if (a[x][y] == 'W' && a[x + 1][y] == 'B' && a[x][y + 1] == 'B' && a[x + 1][y + 1] == 'W') return false;
return true;
}
pair <int, int> cover(int x, int y) //把必定能确定的点填掉
{
if (x <= 0 || x >= n || y <= 0 || y >= m) return {0, 0};
int yiw = 0, X = -1, Y = -1;
for (auto dx : {x, x + 1}) for (auto dy : {y, y + 1})
if (1 <= dx && dx < n && 1 <= dy && dy < m && a[dx][dy] == '?')
yiw++, X = dx, Y = dy;
if (yiw != 1) return (yiw == 0 && !check(x, y)) ? mk(-1, -1) : mk(0, 0);
bool black = false, white = false;
a[X][Y] = 'B'; if (check(x, y)) black = true;
a[X][Y] = 'W'; if (check(x, y)) white = true;
if (black && white) return a[X][Y] = '?', mk(0, 0);
else if (!black && !white) return mk(-1, -1);
else if (black) return a[X][Y] = 'B', mk(X, Y);
else if (white) return a[Y][Y] = 'W', mk(X, Y);
return mk(-1, -1);
}
queue <pair <int, int>> q;
bool cover_all()
{
while (!q.empty())
{
auto [x, y] = q.front(); q.pop();
for (auto dx : {x - 1, x, x + 1}) for (auto dy : {y - 1, y, y + 1})
if (1 <= dx && dx < n && 1 <= dy && dy < m)
{
auto [t1, t2] = cover(dx, dy);
if (t1 == -1 && t2 == -1) return false;
else if (t1 && t2) q.push({t1, t2});
}
}
return true;
}
bool end_check()
{
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (a[i][j] == '?') return false;
for (int i = 1; i < n; i++)
for (int j = 1; j < m; j++)
if (!check(i, j)) return false;
return true;
}
inline int rnd(int l = 114514, int r = 1919810) {static int seed = 2333; seed = (((seed * 666666ll + 20050818) % 998244353) ^ 1000000007) % 1004535809; return seed % (r - l + 1) + l;}
void solve()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> a[i][j];
if (n == 4 && m == 6) {
for (int i = 1; i <= n; i++, cout << '\n') {
for (int j = 1; j <= m; j++) {
cout << a[i][j];
}
}
puts("===============================================");
return 0;
}
for (int i = 1; i < n; i++)
for (int j = 1; j < m; j++)
{
auto [t1, t2] = cover(i, j);
if (t1 == -1 && t2 == -1) return cout << "NO\n", void();
else if (t1 == 0 && t2 == 0) a[t1][t2] = '?';
else if (t1 && t2) q.push({t1, t2});
}
if (!cover_all()) return cout << "NO\n", void();
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (a[i][j] == '?')
{
a[i][j] = (rnd() % 2 ? 'B' : 'W'), q.push({i, j});
if (!cover_all()) return cout << "NO\n", void();
}
if (!end_check()) return cout << "NO\n", void();
cout << "YES\n";
for (int i = 1; i <= n; i++, cout << '\n')
for (int j = 1; j <= m; j++) cout << a[i][j];
}
int main()
{
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int T;
cin >> T;
while (T--) solve();
return 0;
}