#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
const int oo = 1e10;
int t, n, m, a[maxn][maxn], d[maxn][maxn], s[maxn][maxn];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int c1(int x, int y) {
  if (x < 1 || x > n || y < 1 || y > m) return 0;
  return a[x][y];
}
int c2(int x, int y) {
  if (x < 1 || x > n || y < 1 || y > m) return 0;
  return 1;
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    memset(a, 0, sizeof a);
    memset(d, 0, sizeof d);
    memset(s, 0, sizeof s);
    for (int(i) = int(1); int(i) <= int(n); ++i)
      for (int(j) = int(1); int(j) <= int(m); ++j) cin >> a[i][j];
    for (int(i) = int(1); int(i) <= int(n); ++i)
      for (int(j) = int(1); int(j) <= int(m); ++j)
        for (int(z) = int(0); int(z) <= int(3); ++z)
          s[i][j] += c2(i + dx[z], j + dy[z]);
    bool flag = false;
    for (int(i) = int(1); int(i) <= int(n); ++i)
      for (int(j) = int(1); int(j) <= int(m); ++j)
        if (a[i][j] > s[i][j]) flag = true;
    if (flag)
      cout << "NO\n";
    else {
      cout << "YES\n";
      for (int(i) = int(1); int(i) <= int(n); ++i) {
        for (int(j) = int(1); int(j) <= int(m); ++j) cout << s[i][j] << " ";
        cout << "\n";
      }
    }
  }
}
