#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
int a[500][500];
int ans[500][500];
void solve() {}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cin >> a[i][j];
      }
    }
    int f = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (a[i][j] > 4) {
          f = 1;
          break;
        }
        if (a[i][j] == 3) {
          if (i == 1 && j == 1) f = 1;
          if (i == 1 && j == m) f = 1;
          if (i == n && j == 1) f = 1;
          if (i == n && j == m) f = 1;
        }
        if (a[i][j] == 4) {
          if (i == 1 || j == 1 || j == m || i == n) f = 1;
        }
      }
    }
    if (f)
      cout << "NO" << '\n';
    else {
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
          if (i == 1 || j == 1 || i == n || j == m) {
            if ((i == 1 && j == 1) || (i == 1 && j == m) ||
                (i == n && j == 1) || (i == n && j == m))
              ans[i][j] = 2;
            else
              ans[i][j] = 3;
          } else
            ans[i][j] = 4;
        }
      }
      cout << "YES" << '\n';
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
          cout << ans[i][j] << " ";
        }
        cout << '\n';
      }
    }
  }
}
