#include <bits/stdc++.h>
using namespace std;
const int N = 323, bs = 500;
const long long inf = 1e9;
int n, m;
long long a[N][N];
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int nr = 0;
      if (i + 1 <= n) nr += 1;
      if (i - 1 >= 1) nr += 1;
      if (j + 1 <= m) nr += 1;
      if (j - 1 >= 1) nr += 1;
      if (nr < a[i][j]) {
        cout << "NO\n";
        return;
      }
      a[i][j] = nr;
    }
  }
  cout << "YES\n";
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cout << a[i][j] << " ";
    }
    cout << "\n";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
}
