#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T;
  cin >> T;
  while (T--) {
    long long N, M;
    cin >> N >> M;
    vector<vector<long long>> A(N, vector<long long>(M));
    bool stat = true;
    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) || (i == 0 && j == M - 1) ||
             (j == 0 && i == N - 1) || (j == M - 1 && i == N - 1)) &&
            A[i][j] > 2) {
          stat = false;
        } else if ((i == 0 || i == N - 1 || j == 0 || j == M - 1) &&
                   A[i][j] > 3) {
          stat = false;
        } else if (A[i][j] > 4) {
          stat = false;
        }
      }
    }
    if (!stat) {
      cout << "NO\n";
    } else {
      cout << "YES\n";
      for (long long i = 0; i < N; i++) {
        for (long long j = 0; j < M; j++) {
          if ((i == 0 && j == 0) || (i == 0 && j == M - 1) ||
              (j == 0 && i == N - 1) || (j == M - 1 && i == N - 1)) {
            cout << 2 << " ";
          } else if (i == 0 || i == N - 1 || j == 0 || j == M - 1) {
            cout << 3 << " ";
          } else {
            cout << 4 << " ";
          }
        }
        cout << "\n";
      }
    }
  }
  return 0;
}
