#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt, qq;
  cin >> tt;
  for (qq = 1; qq <= tt; qq++) {
    int n, m, i, j, x, f = 0;
    cin >> n >> m;
    int a[n][m];
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        cin >> x;
        if ((i == 0 || i == n - 1) && (j == 0 || j == m - 1)) {
          if (x > 2) {
            f = -1;
          }
          a[i][j] = 2;
        } else if (i == 0 || i == n - 1 || j == 0 || j == m - 1) {
          if (x > 3) {
            f = -1;
          }
          a[i][j] = 3;
        } else {
          if (x > 4) {
            f = -1;
          }
          a[i][j] = 4;
        }
      }
    }
    if (f == -1) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) cout << a[i][j] << " ";
      cout << endl;
    }
  }
}
