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