#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
long long read() {
  long long w = 0;
  char c =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
           ? EOF
           : *p1++);
  while (c < '0' || c > '9')
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  while (c >= '0' && c <= '9')
    w = w * 10 + c - 48,
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
             ? EOF
             : *p1++);
  return w;
}
long long t, n, m, a[305][305];
signed main() {
  t = read();
  while (t--) {
    n = read(), m = read();
    bool flag = 0;
    for (long long i = 1; i <= n; i++)
      for (long long j = 1; j <= m; j++)
        a[i][j] = read(), flag = flag || a[i][j] > 4;
    flag = flag || a[1][1] > 2 || a[1][m] > 2 || a[n][1] > 2 || a[n][m] > 2;
    for (long long i = 1; i <= n; i++)
      flag = flag || a[i][1] > 3 || a[i][m] > 3;
    for (long long i = 1; i <= m; i++)
      flag = flag || a[1][i] > 3 || a[n][i] > 3;
    if (flag) {
      puts("NO");
      continue;
    }
    puts("YES");
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++)
        if (i == 1 && j == 1 || i == 1 && j == m || i == n && j == 1 ||
            i == n && j == m)
          printf("2 ");
        else if (i == 1 || i == n || j == 1 || j == m)
          printf("3 ");
        else
          printf("4 ");
      puts("");
    }
  }
  return 0;
}
