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