#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int n, arr[305][305], m;
int byk[305][305];
bool inside(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    bool u = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cin >> arr[i][j];
      }
    }
    bool good = 1;
    for (int i = 1; i <= n && good; i++) {
      for (int j = 1; j <= m && good; j++) {
        int cnt = 0;
        for (int k = 0; k < 4; k++) {
          int nr = i + dx[k];
          int nc = j + dy[k];
          if (inside(nr, nc)) {
            cnt++;
          }
        }
        if (arr[i][j] > cnt) {
          cout << "NO" << endl;
          good = false;
        }
        arr[i][j] = cnt;
      }
    }
    if (!good) {
      continue;
    }
    cout << "YES" << endl;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cout << arr[i][j] << " ";
      }
      cout << endl;
    }
  }
}
