#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
int n, m, i, j, t;
char mp[25][25], ans[45][45];
vector<pair<int, int> > all, res;
int id(int x, int y) { return (x - 1) * m + y; }
int fa[405], deg[405];
int insert[805], typ[805], g[805][805], pre[805], dis[805];
int fnd(int x) {
  if (fa[x] == x) return x;
  return fa[x] = fnd(fa[x]);
}
void merge(int x, int y) {
  x = fnd(x);
  y = fnd(y);
  fa[x] = y;
}
vector<pair<int, int> > solve(vector<pair<int, int> > v) {
  int i, j, cnt = 0;
  memset((insert), (0), (sizeof((insert))));
  for (;;) {
    cnt++;
    for (((i)) = (1); ((i)) <= ((n * m)); ((i))++) {
      fa[i] = i;
      deg[i] = 0;
    }
    for (((i)) = (0); ((i)) <= (((int)(v.size())) - 1); ((i))++)
      if (insert[i]) {
        merge(v[i].first, v[i].second);
        deg[v[i].first]++;
      }
    for (((i)) = (0); ((i)) <= (((int)(v.size())) - 1); ((i))++) {
      if (insert[i])
        typ[i] = 0;
      else {
        int sx = (fnd(v[i].first) != fnd(v[i].second));
        int sy = (deg[v[i].first] < 2);
        if (sx && sy) {
          insert[i] = 1;
          break;
        }
        typ[i] = sx + sy * 2;
      }
    }
    if (i < v.size()) continue;
    for (((i)) = (0); ((i)) <= (((int)(v.size())) - 1); ((i))++)
      if (insert[i]) {
        for (((j)) = (1); ((j)) <= ((n * m)); ((j))++) {
          fa[j] = j;
          deg[j] = 0;
        }
        for (((j)) = (0); ((j)) <= (((int)(v.size())) - 1); ((j))++)
          if (i != j && insert[j]) {
            merge(v[j].first, v[j].second);
            deg[v[j].first]++;
          }
        for (((j)) = (0); ((j)) <= (((int)(v.size())) - 1); ((j))++)
          if (!insert[j]) {
            int sx = (fnd(v[j].first) != fnd(v[j].second));
            int sy = (deg[v[j].first] < 2);
            g[i][j] = sx;
            g[j][i] = sy;
          }
      }
    queue<int> qx;
    memset((dis), (0x16), (sizeof((dis))));
    for (((i)) = (0); ((i)) <= (((int)(v.size())) - 1); ((i))++)
      if (typ[i] == 1) {
        qx.push(i);
        dis[i] = 0;
      }
    while (!qx.empty()) {
      int x = qx.front();
      qx.pop();
      for (((i)) = (0); ((i)) <= (((int)(v.size())) - 1); ((i))++)
        if (insert[i] != insert[x] && g[x][i]) {
          int z = dis[x] + 1;
          if (dis[i] > z) {
            dis[i] = z;
            pre[i] = x;
            if (typ[i] == 2) break;
            qx.push(i);
          }
        }
      if (i < v.size()) break;
    }
    if (i >= v.size()) break;
    int x = i;
    while (typ[x] != 1) {
      insert[x] ^= 1;
      x = pre[x];
    }
    insert[x] ^= 1;
  }
  vector<pair<int, int> > ans;
  for (((i)) = (0); ((i)) <= (((int)(v.size())) - 1); ((i))++)
    if (insert[i]) {
      ans.push_back(v[i]);
    }
  return ans;
}
void _() {
  read(n);
  read(m);
  for (((i)) = (1); ((i)) <= ((n)); ((i))++)
    for (((j)) = (1); ((j)) <= ((m)); ((j))++) readc(mp[i][j]);
  all.clear();
  for (((i)) = (1); ((i)) <= ((n)); ((i))++)
    for (((j)) = (1); ((j)) <= ((m)); ((j))++)
      if (i + j != 2 && mp[i][j] == 'O') {
        if (i < n && mp[i + 1][j] == 'O')
          if ((i + j) % 2 == 0)
            all.push_back(make_pair(id(i, j), id(i + 1, j)));
          else
            all.push_back(make_pair(id(i + 1, j), id(i, j)));
        if (j < m && mp[i][j + 1] == 'O')
          if ((i + j) % 2 == 0)
            all.push_back(make_pair(id(i, j), id(i, j + 1)));
          else
            all.push_back(make_pair(id(i, j + 1), id(i, j)));
      }
  res = solve(all);
  for (((i)) = (1); ((i)) <= ((n * m)); ((i))++) {
    fa[i] = i;
    deg[i] = 0;
  }
  for (__typeof((res).begin()) it = (res).begin(); it != (res).end(); it++) {
    fa[fnd(it->first)] = fnd(it->second);
    deg[it->first]++;
    deg[it->second]++;
  }
  if (mp[1][2] == 'O') all.push_back(make_pair(id(1, 1), id(1, 2)));
  if (mp[2][1] == 'O') all.push_back(make_pair(id(1, 1), id(2, 1)));
  for (__typeof((all).begin()) it = (all).begin(); it != (all).end(); it++) {
    if (fa[fnd(it->first)] != fnd(it->second)) {
      fa[fnd(it->first)] = fnd(it->second);
      res.push_back(*it);
    }
  }
  for (((i)) = (1); ((i)) <= ((n)); ((i))++)
    for (((j)) = (1); ((j)) <= ((m)); ((j))++)
      if (i + j != 2 && (i + j) % 2 == 0 && mp[i][j] == 'O') {
        if (deg[id(i, j)] < 2) {
          puts("NO");
          return;
        }
      }
  for (((i)) = (1); ((i)) <= ((n + n - 1)); ((i))++)
    for (((j)) = (1); ((j)) <= ((m + m - 1)); ((j))++) ans[i][j] = ' ';
  for (((i)) = (1); ((i)) <= ((n)); ((i))++)
    for (((j)) = (1); ((j)) <= ((m)); ((j))++) {
      ans[i * 2 - 1][j * 2 - 1] = mp[i][j];
    }
  for (__typeof((res).begin()) it = (res).begin(); it != (res).end(); it++) {
    ans[(it->first - 1) / m + (it->second - 1) / m + 1]
       [(it->first - 1) % m + (it->second - 1) % m + 1] = 'O';
  }
  puts("YES");
  for (((i)) = (1); ((i)) <= ((n + n - 1)); ((i))++) {
    for (((j)) = (1); ((j)) <= ((m + m - 1)); ((j))++) putchar(ans[i][j]);
    puts("");
  }
}
int main() {
  read(t);
  while (t--) {
    _();
  }
  return 0;
}
