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