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