#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
const int TS = 2125864;
int n, m, a[303][303];
inline void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> a[i][j];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      if ((i == 1 || i == n) && (j == 1 || j == m) && a[i][j] > 2) {
        cout << "NO\n";
        return;
      }
      if ((i == 1 || i == n || j == 1 || j == m) && a[i][j] > 3) {
        cout << "NO\n";
        return;
      }
      if (a[i][j] > 4) {
        cout << "NO\n";
        return;
      }
      if ((i == 1 || i == n) && (j == 1 || j == m)) {
        a[i][j] = 2;
        continue;
      }
      if ((i == 1 || i == n || j == 1 || j == m)) {
        a[i][j] = 3;
        continue;
      }
      a[i][j] = 4;
    }
  cout << "YES\n";
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) cout << a[i][j] << ' ';
    cout << '\n';
  }
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
