#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 6;
int a[350][350];
int nex[] = {1, -1, 0, 0};
int ney[] = {0, 0, 1, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) cin >> a[i][j];
    int f = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        int countt = 0;
        for (int k = 0; k < 4; k++) {
          int tx = i + nex[k];
          int ty = j + ney[k];
          if (tx >= 1 && tx <= n && ty >= 1 && ty <= m) countt++;
        }
        if (a[i][j] > countt) {
          f = 1;
          break;
        } else
          a[i][j] = countt;
      }
      if (f) break;
    }
    if (f) {
      cout << "NO" << '\n';
    } else {
      cout << "YES" << '\n';
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) cout << a[i][j] << ' ';
        cout << '\n';
      }
    }
  }
  return 0;
}
