#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
  if (x < y) x = y;
}
int read() {
  char c;
  while ((c = getchar()) < '-')
    ;
  if (c == '-') {
    int x = (c = getchar()) - '0';
    while ((c = getchar()) >= '0') x = x * 10 + c - '0';
    return -x;
  }
  int x = c - '0';
  while ((c = getchar()) >= '0') x = x * 10 + c - '0';
  return x;
}
namespace BING {
const int N = 400 + 5;
int fa[N];
void init() {
  for (int i = 1; i <= N - 1; ++i) fa[i] = i;
}
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void merge(const pair<int, int> &e) { fa[find(e.first)] = find(e.second); }
bool con(const pair<int, int> &e) { return find(e.first) == find(e.second); }
};  // namespace BING
const int N = 20 + 5, M = 400 * 2 + 5;
char s[N][N];
int n1, n2, m;
pair<int, int> e[M];
bool in[M], lk[M][M];
int g[M], q[M], fr[M], tail;
int leave[N * N];
void leave_add(int i, int w) {
  leave[e[i].first] += w;
  leave[e[i].second] += w;
}
void leave_init() {
  for (int i = 1; i <= n1; ++i)
    for (int j = 1; j <= n2; ++j) leave[(i - 1) * n2 + j] = (i + j) % 2 ? 4 : 2;
  leave[1] = 0;
  for (int i = 1; i <= m; ++i)
    if (in[i]) leave_add(i, -1);
}
void push(int x, int y, int d) {
  if (g[x] > d) {
    g[x] = d;
    fr[x] = y;
    q[++tail] = x;
  }
}
int bfs() {
  leave_init();
  for (int i = 1; i <= m; ++i)
    if (in[i]) {
      BING::init();
      for (int j = 1; j <= m; ++j)
        if (in[j] && j != i) BING::merge(e[j]);
      for (int j = 1; j <= m; ++j)
        if (!in[j]) lk[i][j] = !BING::con(e[j]);
    }
  tail = 0;
  BING::init();
  for (int i = 1; i <= m; ++i)
    if (in[i]) BING::merge(e[i]);
  for (int i = 1; i <= m; ++i) {
    g[i] = m;
    if (!in[i] && !BING::con(e[i])) push(i, 0, 0);
  }
  for (int head = 1; head <= tail; ++head) {
    int x = q[head];
    if (in[x]) {
      for (int y = 1; y <= m; ++y)
        if (!in[y] && lk[x][y]) push(y, x, g[x] + 1);
    } else {
      if (leave[e[x].first] && leave[e[x].second]) return x;
      for (int y = 1; y <= m; ++y)
        if (in[y]) {
          leave_add(y, 1);
          if (leave[e[x].first] && leave[e[x].second]) push(y, x, g[x] + 1);
          leave_add(y, -1);
        }
    }
  }
  return 0;
}
void work() {
  cin >> n1 >> n2;
  m = 0;
  for (int i = 1; i <= n1; ++i) scanf("%s", s[i] + 1);
  auto check = [&](int x1, int y1, int x2, int y2) {
    if (s[x1][y1] == 'O' && s[x2][y2] == 'O')
      e[++m] = pair<int, int>((x1 - 1) * n2 + y1, (x2 - 1) * n2 + y2);
  };
  for (int i = 1; i <= n1; ++i)
    for (int j = 1; j <= n2 - 1; ++j) check(i, j, i, j + 1);
  for (int i = 1; i <= n1 - 1; ++i)
    for (int j = 1; j <= n2; ++j) check(i, j, i + 1, j);
  for (int i = 1; i <= m; ++i) in[i] = 0;
  int x;
  while ((x = bfs()))
    for (; x; x = fr[x]) in[x] ^= 1;
  int Bcnt = 0;
  for (int i = 1; i <= n1; ++i)
    for (int j = 1; j <= n2; ++j)
      if ((i + j) % 2 == 0 && s[i][j] == 'O') ++Bcnt;
  set<pair<int, int> > S;
  BING::init();
  for (int i = 1; i <= m; ++i)
    if (in[i]) {
      S.insert(e[i]);
      BING::merge(e[i]);
    }
  if (S.size() != (Bcnt - 1) * 2) {
    puts("NO");
    return;
  }
  for (int i = 1; i <= m; ++i)
    if (!BING::con(e[i])) {
      S.insert(e[i]);
      BING::merge(e[i]);
    }
  puts("YES");
  for (int i = 1; i <= n1; ++i) {
    for (int j = 1; j <= n2; ++j) {
      printf("%c", s[i][j]);
      if (j < n2)
        putchar(S.count(pair<int, int>((i - 1) * n2 + j, (i - 1) * n2 + j + 1))
                    ? 'O'
                    : ' ');
    }
    puts("");
    if (i < n1) {
      for (int j = 1; j <= n2; ++j) {
        putchar(S.count(pair<int, int>((i - 1) * n2 + j, i * n2 + j)) ? 'O'
                                                                      : ' ');
        if (j < n2) putchar(' ');
      }
      puts("");
    }
  }
}
int main() {
  int tt;
  cin >> tt;
  while (tt--) work();
}
