#include <bits/stdc++.h>
using namespace std;
const int mod = (1e9) + 7;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> arr(n, vector<int>(m, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> arr[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i == 0 || i == n - 1) {
        if (j == 0 || j == m - 1) {
          arr[i][j] = max(arr[i][j], 2);
        } else {
          arr[i][j] = max(arr[i][j], 3);
        }
        continue;
      }
      if (j == 0 || j == m - 1) {
        if (i == 0 || i == n - 1) {
          arr[i][j] = max(arr[i][j], 2);
        } else {
          arr[i][j] = max(arr[i][j], 3);
        }
        continue;
      } else {
        arr[i][j] = max(arr[i][j], 4);
      }
    }
  }
  auto check = [&](int i, int j) {
    return (i >= 0) && (j >= 0) && (i < n) && (j < m);
  };
  bool pos = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int ng = 0;
      if (check(i - 1, j)) ng++;
      if (check(i + 1, j)) ng++;
      if (check(i, j - 1)) ng++;
      if (check(i, j + 1)) ng++;
      if (arr[i][j] > ng) {
        pos = 0;
      }
    }
  }
  if (pos) {
    cout << "YES" << endl;
    for (auto i : arr) {
      for (auto j : i) {
        cout << j << " ";
      }
      cout << endl;
    }
  } else {
    cout << "NO" << endl;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
