#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m, arr[303][303];
    scanf("%d %d", &n, &m);
    bool can = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        scanf("%d", &arr[i][j]);
        if (i == 0 || i == n - 1) {
          if (j > 0 && j < m - 1) {
            if (arr[i][j] > 3) can = false;
            arr[i][j] = 3;
          } else {
            if (arr[i][j] > 2) can = false;
            arr[i][j] = 2;
          }
        } else if (j == 0 || j == m - 1) {
          if (i > 0 && i < n - 1) {
            if (arr[i][j] > 3) can = false;
            arr[i][j] = 3;
          } else {
            if (arr[i][j] > 2) can = false;
            arr[i][j] = 2;
          }
        } else {
          if (arr[i][j] > 4) can = false;
          arr[i][j] = 4;
        }
      }
    }
    if (!can) {
      printf("NO\n");
      continue;
    }
    printf("YES\n");
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        printf("%d%c", arr[i][j], j >= m - 1 ? '\n' : ' ');
      }
    }
  }
  return 0;
}
