#include <bits/stdc++.h>
using namespace std;
const int maxn = 305;
int a[maxn][maxn], b[maxn][maxn];
int main(int argc, char const *argv[]) {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        scanf("%d", &a[i][j]);
      }
    }
    bool good = 1;
    b[1][1] = b[1][m] = b[n][1] = b[n][m] = 2;
    if (a[1][1] > 2 or a[1][m] > 2 or a[n][1] > 2 or a[n][m] > 2) {
      printf("NO\n");
      continue;
    }
    for (int i = 2; i < m; ++i) {
      if (a[1][i] > 3 or a[n][i] > 3) {
        good = 0;
      }
      b[1][i] = b[n][i] = 3;
    }
    for (int i = 2; i < n; ++i) {
      if (a[i][1] > 3 or a[i][m] > 3) {
        good = 0;
      }
      b[i][1] = b[i][m] = 3;
    }
    if (!good) {
      printf("NO\n");
      continue;
    }
    for (int i = 2; i < n; ++i) {
      for (int j = 2; j < m; ++j) {
        if (a[i][j] > 4) {
          good = 0;
        }
        b[i][j] = 4;
      }
    }
    if (!good) {
      printf("NO\n");
    } else {
      printf("YES\n");
      for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
          printf("%d ", b[i][j]);
        }
        printf("\n");
      }
    }
  }
  return 0;
}
