#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
void solve() {
  int n, m;
  cin >> n >> m;
  int a[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int ans[n][m];
  bool pos = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if ((i == 0 && j == 0) || (i == n - 1 && j == 0) ||
          (i == 0 && j == m - 1) || (i == n - 1 && j == m - 1)) {
        ans[i][j] = 2;
      } else if ((i == 0 && j > 0 && j < m - 1) ||
                 (j == 0 && i > 0 && i < n - 1) ||
                 (j == m - 1 && i > 0 && i < n - 1) ||
                 (i == n - 1 && j > 0 && j < m - 1)) {
        ans[i][j] = 3;
      } else {
        ans[i][j] = 4;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] > ans[i][j]) {
        pos = false;
      }
    }
  }
  if (pos) {
    cout << "YES\n";
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << ans[i][j] << ' ';
      }
      cout << '\n';
    }
  } else {
    cout << "NO\n";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
