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