#include <bits/stdc++.h>
using namespace std;
const int maxn = 2100;
const int inf = 1e9 + 7;
const long long mod = 1e9 + 7;
int a[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int tc = 0; tc < t; tc++) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
      }
    }
    bool ok = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if ((i == 0 || i == n - 1) && (j == 0 || j == m - 1)) {
          if (a[i][j] > 2) {
            ok = false;
            break;
          }
        } else if (i == 0 || i == n - 1 || j == 0 || j == m - 1) {
          if (a[i][j] > 3) {
            ok = false;
            break;
          }
        } else {
          if (a[i][j] > 4) {
            ok = false;
            break;
          }
        }
      }
      if (!ok) {
        break;
      }
    }
    if (!ok) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if ((i == 0 || i == n - 1) && (j == 0 || j == m - 1)) {
            cout << 2 << " ";
          } else if (i == 0 || i == n - 1 || j == 0 || j == m - 1) {
            cout << 3 << " ";
          } else {
            cout << 4 << " ";
          }
        }
        cout << endl;
      }
    }
  }
}
