#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { cout << '\n'; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << '[' << *it << " = " << a << "]  ";
  err(++it, args...);
}
mt19937 rng(
    (unsigned int)chrono::steady_clock::now().time_since_epoch().count());
int rnd(int a, int b) { return a + (rng() % (b - a + 1)); }
const long long int M = 1000000007ll;
const double D = 1.0;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
void solve() {
  int n, m, y, x;
  cin >> n >> m;
  bool ans = true;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> y;
      if ((i == 0 and j == 0) or (i == 0 and j == m - 1) or
          (i == n - 1 and j == 0) or (i == n - 1 and j == m - 1)) {
        x = 2;
      } else if (i == 0 or j == 0 or i == n - 1 or j == m - 1) {
        x = 3;
      } else {
        x = 4;
      }
      if (y > x) {
        ans = false;
      }
    }
  }
  if (!ans) {
    cout << "NO\n";
    return;
  }
  cout << "YES\n";
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if ((i == 0 and j == 0) or (i == 0 and j == m - 1) or
          (i == n - 1 and j == 0) or (i == n - 1 and j == m - 1)) {
        x = 2;
      } else if (i == 0 or j == 0 or i == n - 1 or j == m - 1) {
        x = 3;
      } else {
        x = 4;
      }
      cout << x << " ";
    }
    cout << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc = 1;
  cin >> tc;
  while (tc--) {
    solve();
  }
  return 0;
}
