#include <bits/stdc++.h>
using namespace std;
inline long long rint() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
inline long long gcd(long long a, long long b) {
  return (b) ? gcd(b, a % b) : a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long pow(long long a, long long b, long long q) {
  long long rtn = 1;
  while (b) {
    if (b & 1) rtn = rtn * a % q;
    a = a * a % q;
    b >>= 1;
  }
  return rtn;
}
inline long long mysqrt(long long n) {
  long long x = sqrt(n);
  while (x * x < n) x++;
  while (x * x > n) x--;
  return x;
}
int v[305][305];
void solve() {
  int n = rint(), m = rint();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) v[i][j] = rint();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if ((i == 1 || i == n) && (j == 1 || j == m)) {
        if (v[i][j] > 2) {
          cout << "NO"
               << "\n";
          return;
        }
      } else if (i == 1 || i == n || j == 1 || j == m) {
        if (v[i][j] > 3) {
          cout << "NO"
               << "\n";
          return;
        }
      } else {
        if (v[i][j] > 4) {
          cout << "NO"
               << "\n";
          return;
        }
      }
    }
  }
  cout << "YES"
       << "\n";
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if ((i == 1 || i == n) && (j == 1 || j == m))
        cout << 2 << " ";
      else if ((i == 1 || i == n) || (j == 1 || j == m))
        cout << 3 << " ";
      else
        cout << 4 << " ";
    }
    cout << "\n";
  }
}
int main() {
  int t = rint();
  while (t--) solve();
}
