#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
signed main() {
  int q;
  cin >> q;
  while (q--) {
    int n, m, ok = 0;
    cin >> n >> m;
    v.assign(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> v[i][j];
      }
    }
    for (int i = 0; i < n; i++) {
      if (ok) {
        break;
      }
      for (int j = 0; j < m; j++) {
        if (ok) {
          break;
        }
        if (i == 0 || i == n - 1) {
          if (j == 0 || j == m - 1) {
            if (v[i][j] > 2) {
              cout << "NO\n";
              ok = 1;
            } else {
              v[i][j] = 2;
            }
          } else {
            if (v[i][j] > 3) {
              cout << "NO\n";
              ok = 1;
            } else {
              v[i][j] = 3;
            }
          }
        } else if (j == 0 || j == m - 1) {
          if (i == 0 || i == n - 1) {
            if (v[i][j] > 2) {
              cout << "NO\n";
              ok = 1;
            } else {
              v[i][j] = 2;
            }
          } else {
            if (v[i][j] > 3) {
              cout << "NO\n";
              ok = 1;
            } else {
              v[i][j] = 3;
            }
          }
        } else {
          if (v[i][j] > 4) {
            cout << "NO\n";
            ok = 1;
          } else {
            v[i][j] = 4;
          }
        }
      }
    }
    if (ok) {
      continue;
    }
    cout << "YES\n";
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << v[i][j] << " ";
      }
      cout << "\n";
    }
  }
  return 0;
}
