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