#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};
int n, m;
bool is_corr(int a, int b) { return a >= 0 && a < n && b >= 0 && b < m; }
signed main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    bool pos = true;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        int a;
        cin >> a;
        int b = 0;
        for (int ii = 0; ii < 4; ++ii) {
          if (is_corr(i + dx[ii], j + dy[ii])) {
            ++b;
          }
        }
        if (b < a) {
          pos = false;
        }
      }
    }
    if (pos) {
      cout << "YES\n";
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
          int b = 0;
          for (int ii = 0; ii < 4; ++ii) {
            if (is_corr(i + dx[ii], j + dy[ii])) {
              ++b;
            }
          }
          cout << b << " ";
        }
        cout << "\n";
      }
    } else {
      cout << "NO\n";
    }
  }
}
