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