#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << "\n";
  err(++it, args...);
}
const int M = 1e9 + 7, N = 2e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int a[n][m], b[n][m];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) cin >> a[i][j];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int c = 0;
        if (i - 1 >= 0) c++;
        if (i + 1 <= n - 1) c++;
        if (j - 1 >= 0) c++;
        if (j + 1 <= m - 1) c++;
        b[i][j] = c;
      }
    }
    bool red = false;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i][j] > b[i][j]) {
          red = true;
          break;
        }
      }
      if (red) break;
    }
    if (red)
      cout << "NO"
           << "\n";
    else {
      cout << "YES"
           << "\n";
      for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) cout << b[i][j] << " \n"[j == m - 1];
      ;
    }
  }
}
