#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " : " << a << endl;
  err(++it, args...);
}
int dy[] = {-1, 1, 0, 0};
int dx[] = {0, 0, -1, 1};
const int N = 305;
int arr[N][N];
int main() {
  int cas;
  cin >> cas;
  while (cas--) {
    int n, m;
    cin >> n >> m;
    for (long long int i = 1; i < (n + 1); ++i) {
      for (long long int j = 1; j < (m + 1); ++j) {
        int cnt = 0;
        for (long long int k = 0; k < (4); ++k) {
          int ny = i + dy[k], nx = j + dx[k];
          if (ny <= 0 or nx <= 0 or ny > n or nx > m) continue;
          cnt++;
        }
        arr[i][j] = cnt;
      }
    }
    bool chi = true;
    for (long long int i = 1; i < (n + 1); ++i) {
      for (long long int j = 1; j < (m + 1); ++j) {
        int fo;
        cin >> fo;
        if (fo > arr[i][j]) chi = false;
      }
    }
    if (chi) {
      cout << "YES" << endl;
      for (long long int i = 1; i < (n + 1); ++i) {
        for (long long int j = 1; j < (m + 1); ++j) cout << arr[i][j] << " ";
        cout << endl;
      }
    } else
      cout << "NO" << endl;
  }
  return 0;
}
