#include <bits/stdc++.h>
using namespace std;
int g[333][333];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    bool ch = true;
    for (long long i = 1; i <= n; i++)
      for (long long j = 1; j <= m; j++) {
        int cur = 4, a;
        scanf("%d", &a);
        if (i == 1) cur--;
        if (i == n) cur--;
        if (j == 1) cur--;
        if (j == m) cur--;
        if (cur < a) ch = false;
        g[i][j] = cur;
      }
    if (ch == false) printf("NO\n");
    if (ch) {
      printf("YES\n");
      for (long long i = 1; i <= n; i++)
        for (long long j = 1; j <= m; j++) {
          printf("%d", g[i][j]);
          if (j == m)
            printf("\n");
          else
            printf(" ");
        }
    }
  }
  return 0;
}
