#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--) {
    int n, m;
    cin >> n >> m;
    int grid[n][m];
    bool flag = false;
    auto validCellCount = [&](int x, int y) {
      int cnt = 0;
      for (int i = 0; i < 4; i++) {
        int nx = x + dr[i];
        int ny = y + dc[i];
        cnt += (nx >= 0 && nx < n && ny >= 0 && ny < m);
      }
      return cnt;
    };
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> grid[i][j];
        if (validCellCount(i, j) < grid[i][j]) flag = true;
      }
    }
    if (flag)
      cout << "NO" << '\n';
    else {
      cout << "YES" << '\n';
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          grid[i][j] = validCellCount(i, j);
          cout << grid[i][j] << ' ';
        }
        cout << '\n';
      }
    }
  }
}
