#include <bits/stdc++.h>
using namespace std;
long long int i, j;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int binpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res % 1000000007;
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    long long int a[n][m];
    for (i = 0; i < n; i++)
      for (j = 0; j < m; j++) cin >> a[i][j];
    long long int in = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if ((i == 0 && j == 0) || (i == 0 && j == m - 1) ||
            (i == n - 1 && j == m - 1) || (j == 0 && i == n - 1)) {
          if (a[i][j] > 2) {
            in = 1;
            break;
          } else
            a[i][j] = 2;
        } else if (i == 0 || i == n - 1 || j == 0 || j == m - 1) {
          if (a[i][j] > 3) {
            in = 1;
            break;
          } else
            a[i][j] = 3;
        } else {
          if (a[i][j] > 4) {
            in = 1;
            break;
          } else
            a[i][j] = 4;
        }
      }
      if (in) break;
    }
    if (in)
      cout << "NO\n";
    else {
      cout << "YES\n";
      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
          cout << a[i][j] << " ";
        }
        cout << endl;
      }
    }
  }
}
