#include <bits/stdc++.h>
using namespace std;
int main() {
  long int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    long int a[n + 1][m + 1];
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cin >> a[i][j];
      }
    }
    long int b[n + 1][m + 1];
    for (int i = 1; i <= n; i++) {
      b[i][1] = 3;
      b[i][m] = 3;
    }
    for (int i = 1; i <= m; i++) {
      b[1][i] = 3;
      b[n][i] = 3;
    }
    b[1][1] = 2;
    b[1][m] = 2;
    b[n][1] = 2;
    b[n][m] = 2;
    for (int i = 2; i <= n - 1; i++) {
      for (int j = 2; j <= m - 1; j++) {
        b[i][j] = 4;
        b[i][j] = 4;
      }
    }
    int f = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (a[i][j] > b[i][j]) {
          f = 1;
          break;
        }
      }
    }
    if (f == 1) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
          cout << b[i][j] << " ";
        }
        cout << endl;
      }
    }
  }
}
