#include <bits/stdc++.h>
using namespace std;
void prntV(vector<long long int> v) {
  cout << "\n"
       << "\n"
       << "vector size: " << v.size() << "  \nthe vector: ";
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << "\n"
       << "\n";
}
void prntA(long long int a[]) {
  cout << "\n"
       << "\n"
       << "size of the array: " << (sizeof(a) / sizeof(a[0]))
       << "\nthe array is: ";
  for (long long int i = 0; i < (sizeof(a) / sizeof(a[0])); i++) {
    cout << a[i] << " ";
  }
  cout << "\n"
       << "\n";
}
void solve() {
  int n, m;
  cin >> n >> m;
  int a[n][m];
  bool what = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (i == 0 && what) {
        if (j == 0 || j == m - 1) {
          if (a[i][j] <= 2)
            a[i][j] = 2;
          else
            what = false;
        } else {
          if (a[i][j] <= 3)
            a[i][j] = 3;
          else
            what = false;
        }
      } else if (i == n - 1 && what) {
        if (j == 0 || j == m - 1) {
          if (a[i][j] <= 2)
            a[i][j] = 2;
          else
            what = false;
        } else {
          if (a[i][j] <= 3)
            a[i][j] = 3;
          else
            what = false;
        }
      } else if ((j == 0 || j == m - 1) && what) {
        if (a[i][j] <= 3)
          a[i][j] = 3;
        else
          what = false;
      } else if (what) {
        if (a[i][j] <= 4)
          a[i][j] = 4;
        else
          what = false;
      }
    }
  }
  if (what) {
    cout << "YES"
         << "\n";
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << a[i][j] << " ";
      }
      cout << "\n";
    }
  } else
    cout << "NO"
         << "\n";
  return;
}
int main() {
  int tc = 10;
  cin >> tc;
  while (tc--) {
    solve();
    cout << "\n";
  }
  return 0;
}
