#include <bits/stdc++.h>
using namespace std;
const long long int M = 1e9 + 7;
const long long int N = 1e5 + 5;
const long long int inf = 2e18;
long long int mod(long long int x) { return (x % M); }
long long int mod_minus(long long int a, long long int b) {
  long long int ans = (mod(a) - mod(b));
  if (ans < 0) ans = mod(ans + M);
  return ans;
}
long long int mod_mul(long long int a, long long int b) {
  return mod(mod(a) * mod(b));
}
long long int mod_add(long long int a, long long int b) {
  return mod(mod(a) + mod(b));
}
long long int power(long long int a, long long int n) {
  if (n == 0)
    return 1;
  else if (n == 1)
    return a;
  long long int R = power(a, n / 2) % M;
  if (n % 2 == 0) {
    return mod(mod_mul(R, R));
  } else {
    return mod(mod_mul(mod_mul(R, a), mod(R)));
  }
}
long long int mod_div(long long int a, long long int b) {
  long long int ans = mod(a);
  long long int b1 = power(b, M - 2);
  ans = mod(mod_mul(ans, b1));
  return ans;
}
long long int fact_mod(long long int n) {
  vector<long long int> fact(n + 1);
  fact[0] = 1;
  for (long long int i = 1; i < n + 1; i++) {
    fact[i] = mod_mul(fact[i - 1], i);
  }
  return fact[n];
}
long long int nCr_mod(long long int n, long long int r) {
  return mod(mod_mul(mod_mul(fact_mod(n), mod(fact_mod(power(r, M - 2)))),
                     mod(power(fact_mod(n - r), M - 2))));
}
template <typename T>
class Cpoint {
 public:
  T x, y, z;
  Cpoint(T tmp_x, T tmp_y = 0, T tmp_z = 0) {
    x = tmp_x;
    y = tmp_y;
    z = tmp_z;
  }
  Cpoint operator+(Cpoint b) {
    return Cpoint(this->x + b.x, this->y + b.y, this->z + b.z);
  }
  Cpoint operator-(Cpoint b) {
    return Cpoint(this->x - b.x, this->y - b.y, this->z - b.z);
  }
  Cpoint& operator+=(Cpoint b) {
    *this = *this + b;
    return *this;
  }
};
template <typename T>
T dot(Cpoint<T> a, Cpoint<T> b) {
  return a.x * b.x + a.y * b.y + a.z * b.z;
}
template <typename T>
float ang(Cpoint<T> a, Cpoint<T> b) {
  return acos(dot(a, b) / sqrt(dot(a, a) * dot(b, b)));
}
pair<long long int, long long int> Egcd(long long int a, long long int b) {
  if (b == 0) return make_pair(1, 0);
  pair<long long int, long long int> t = Egcd(b, a % b);
  return make_pair(t.second, t.first - (a / b) * t.second);
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  vector<vector<long long int> > a(n + 1, vector<long long int>(m + 1));
  long long int i, j;
  bool f = true;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  if (a[0][0] > 2 || a[n - 1][0] > 2 || a[0][m - 1] > 2 ||
      a[n - 1][m - 1] > 2) {
    cout << "NO" << endl;
    return;
  }
  a[0][0] = a[n - 1][0] = a[0][m - 1] = a[n - 1][m - 1] = 2;
  for (i = 1; i < n - 1; i++) {
    if (a[i][0] > 3 || a[i][m - 1] > 3) {
      cout << "NO" << endl;
      return;
    }
    a[i][0] = a[i][m - 1] = 3;
  }
  for (i = 1; i < m - 1; i++) {
    if (a[0][i] > 3 || a[n - 1][i] > 3) {
      cout << "NO" << endl;
      return;
    }
    a[0][i] = a[n - 1][i] = 3;
  }
  for (i = 1; i < n - 1; i++) {
    for (j = 1; j < m - 1; j++) {
      if (a[i][j] > 4) {
        cout << "NO" << endl;
        return;
      }
      a[i][j] = 4;
    }
  }
  cout << "YES" << endl;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) cout << a[i][j] << ' ';
    cout << endl;
  }
}
int main() {
  long long int t;
  cin >> t;
  while (t--) solve();
}
