#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793;
const int MOD = 1e9 + 7;
long long power(long long x, long long y, long long m) {
  long long res = 1;
  x %= m;
  while (y > 0) {
    if (y & 1) res = (res * x) % m;
    y >>= 1;
    x = (x * x) % m;
  }
  return res % m;
}
void solve() {
  int n, m;
  cin >> n >> m;
  long long a[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[i][j];
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      count = 0;
      if (a[i][j] > 4) {
        cout << "NO\n";
        return;
      } else {
        if ((i == 0 || i == n - 1) && (j == 0 || j == m - 1))
          count = 2;
        else if ((i == 0) || (j == 0) || i == n - 1 || j == m - 1)
          count = 3;
        else
          count = 4;
        if (a[i][j] > count) {
          cout << "NO\n";
          return;
        }
        a[i][j] = count;
      }
    }
  }
  cout << "YES\n";
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << a[i][j] << " ";
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
