#include <bits/stdc++.h>
using namespace std;
const long long int MAXN = 5e5 + 5;
const long long int mod = 1e9 + 7;
const long double pi = 3.141592653;
long long int a[500][500];
void solve() {
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      long long int f = 0;
      if (i - 1 >= 0) f++;
      if (j - 1 >= 0) f++;
      if (i + 1 < n) f++;
      if (j + 1 < m) f++;
      if (a[i][j] > f) {
        cout << "NO\n";
        return;
      }
      a[i][j] = f;
    }
  }
  cout << "YES\n";
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) solve();
  cerr << "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << "ms"
       << '\n';
  return 0;
}
