#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    bool hbe = true;
    int n, m, a;
    cin >> n >> m;
    int ar[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cin >> ar[i][j];
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int ne = 0;
        if (i > 0) ne++;
        if (i < n - 1) ne++;
        if (j > 0) ne++;
        if (j < m - 1) ne++;
        if (ar[i][j] > ne) {
          hbe = false;
          break;
        }
        ar[i][j] = ne;
      }
      if (!hbe) break;
    }
    if (!hbe)
      cout << "NO"
           << "\n";
    else {
      cout << "YES"
           << "\n";
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          cout << ar[i][j] << " ";
        }
        cout << "\n";
      }
    }
  }
  return 0;
}
