#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 9;
const long long maxn = 3e2 + 9;
long long a[maxn][maxn];
pair<long long, long long> q[N];
long long front, rear;
long long dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
bool vis[maxn][maxn];
void solve() {
  memset(vis, 0, sizeof(vis));
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  if (a[1][1] > 2 || a[n][m] > 2 || a[1][m] > 2 || a[n][1] > 2) {
    cout << "NO" << endl;
    return;
  }
  a[1][1] = a[n][m] = a[1][m] = a[n][1] = 2;
  for (long long i = 2; i <= n - 1; i++) {
    if (a[i][1] > 3 || a[i][m] > 3) {
      cout << "NO" << endl;
      return;
    } else {
      a[i][1] = a[i][m] = 3;
    }
  }
  for (long long i = 2; i <= m - 1; i++) {
    if (a[1][i] > 3 || a[n][i] > 3) {
      cout << "NO" << endl;
      return;
    } else {
      a[1][i] = a[n][i] = 3;
    }
  }
  for (long long i = 2; i <= n - 1; i++) {
    for (long long j = 2; j <= m - 1; j++) {
      if (a[i][j] > 4) {
        cout << "NO" << endl;
        return;
      } else {
        a[i][j] = 4;
      }
    }
  }
  cout << "YES" << endl;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}
signed main() {
  long long _;
  cin >> _;
  while (_--) solve();
}
