#include <bits/stdc++.h>
using namespace std;
int t;
int n, m;
int a[301][301];
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    bool ok = true;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        cin >> a[i][j];
        if ((i == 1 || j == 1 || i == n || j == m) && a[i][j] >= 4) ok = false;
        if (((i == 1 && j == 1) || (i == 1 && j == m) || (i == n && j == 1) ||
             (i == n && j == m)) &&
            a[i][j] >= 3)
          ok = false;
        if (a[i][j] >= 5) ok = false;
      }
    if (!ok) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if ((i == 1 && j == 1) || (i == 1 && j == m) || (i == n && j == 1) ||
            (i == n && j == m))
          cout << 2 << ' ';
        else if (i == 1 || j == 1 || i == n || j == m)
          cout << 3 << ' ';
        else
          cout << 4 << ' ';
      }
      cout << '\n';
    }
  }
}
