#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
label:
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    int arr[n][m];
    int i, j;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        scanf("%d", &arr[i][j]);
        if (arr[i][j] == 0) arr[i][j] = 1;
      }
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (arr[i][j] > 4) {
          printf("NO\n");
          goto label;
        } else if (arr[i][j] == 3) {
          if (i == 0 && j == 0 || i == n - 1 && j == 0 ||
              i == 0 && j == m - 1 || i == n - 1 && j == m - 1) {
            printf("NO\n");
            goto label;
          }
        } else if (arr[i][j] == 4) {
          if (i == 0 || j == 0 || i == n - 1 || j == m - 1) {
            printf("NO\n");
            goto label;
          }
        }
      }
    }
    printf("YES\n");
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (i == 0 && j == 0 || i == n - 1 && j == 0 || i == 0 && j == m - 1 ||
            i == n - 1 && j == m - 1) {
          printf("2 ");
          if (j == m - 1) printf("\n");
        } else if (i == 0 || j == 0 || i == n - 1 || j == m - 1) {
          printf("3 ");
          if (j == m - 1) printf("\n");
        } else {
          printf("4 ");
          if (j == m - 1) printf("\n");
        }
      }
    }
  }
  return 0;
}
