#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int maxdegree(int n, int m, int i, int j) {
  int d = 0;
  if (i == 0 || i == n - 1)
    d += 1;
  else
    d += 2;
  if (j == 0 || j == m - 1)
    d += 1;
  else
    d += 2;
  return d;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<vector<int> > a(n, vector<int>(m));
    for (int i = 0; i < n; ++i)
      for (int i_ = 0; i_ < (int)a[i].size(); ++i_) cin >> a[i][i_];
    string ans = "YES";
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j)
        if (a[i][j] > maxdegree(n, m, i, j)) ans = "NO";
    cout << ans << '\n';
    if (ans == "YES")
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) cout << maxdegree(n, m, i, j) << " ";
        cout << '\n';
      }
  }
  exit(0);
}
