#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    int flag = 1;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        int num;
        scanf("%d", &num);
        if ((i == 1 && (j == 1 || j == m)) || (i == n && (j == 1 || j == m))) {
          if (num > 2) flag = 0;
        } else if ((i == 1 || j == 1 || j == m || i == n) && num >= 4)
          flag = 0;
        else if (num > 4)
          flag = 0;
      }
    }
    if (flag) {
      printf("YES\n");
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
          if ((i == 1 && (j == 1 || j == m)) || (i == n && (j == 1 || j == m)))
            printf("2 ");
          else if (i == 1 || j == 1 || i == n || j == m)
            printf("3 ");
          else
            printf("4 ");
        }
        printf("\n");
      }
    } else
      printf("NO\n");
  }
  return 0;
}
