#include <bits/stdc++.h>
using namespace std;
void AME() { cout << fixed << setprecision(0); }
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    long long a[n + 1][m + 1];
    bool flag = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
        if (flag) continue;
        if (i == 0 && j == 0 || i == 0 && j == m - 1 || i == n - 1 && j == 0 ||
            i == n - 1 && j == m - 1) {
          if (a[i][j] > 2) {
            flag = 1;
          } else {
            a[i][j] = 2;
          }
        } else if (i == 0 && j > 0 && j < m - 1 ||
                   i == n - 1 && j > 0 && j < m - 1 ||
                   j == 0 && i > 0 && i < n - 1 ||
                   j == m - 1 && i > 0 && i < n - 1) {
          if (a[i][j] > 3) {
            flag = 1;
          } else {
            a[i][j] = 3;
          }
        } else {
          if (a[i][j] > 4) {
            flag = 1;
          } else {
            a[i][j] = 4;
          }
        }
      }
    }
    if (flag) {
      cout << "NO\n";
    } else {
      cout << "YES\n";
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          cout << a[i][j] << " ";
        }
        cout << "\n";
      }
    }
  }
  return 0;
}
