#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    int n, i, j, m, flag = 1;
    cin >> n >> m;
    int a[n][m];
    for (i = 0; i <= n - 1; i++) {
      for (j = 0; j <= m - 1; j++) cin >> a[i][j];
    }
    if (a[0][0] > 2 || a[n - 1][0] > 2 || a[0][m - 1] > 2 ||
        a[n - 1][m - 1] > 2) {
      flag = 0;
    }
    a[0][0] = 2;
    a[n - 1][0] = 2, a[0][m - 1] = 2, a[n - 1][m - 1] = 2;
    if (flag == 0) {
      cout << "NO" << '\n';
      continue;
    }
    for (i = 1; i < m - 1; i++) {
      if (a[0][i] > 3 || a[n - 1][i] > 3) {
        flag = 0;
        break;
      }
      a[0][i] = 3;
      a[n - 1][i] = 3;
    }
    for (i = 1; i < n - 1; i++) {
      if (a[i][0] > 3 || a[i][m - 1] > 3) {
        flag = 0;
        break;
      }
      a[i][0] = 3;
      a[i][m - 1] = 3;
    }
    for (i = 1; i < n - 1; i++) {
      for (j = 1; j < m - 1; j++) {
        if (a[i][j] > 4) {
          flag = 0;
          break;
        }
        a[i][j] = 4;
      }
      if (flag == 0) break;
    }
    if (flag == 0)
      cout << "NO" << '\n';
    else {
      cout << "YES" << '\n';
      for (i = 0; i <= n - 1; i++) {
        for (j = 0; j <= m - 1; j++) {
          cout << a[i][j] << " ";
        }
        cout << '\n';
      }
    }
  }
}
