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