#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("trapv")
using namespace std;
long long power(long long x, long long y, long long m) {
  if (y < 0) return 0;
  long long temp;
  if (y == 0) return 1;
  temp = (power(x, y / 2, m)) % m;
  if (y % 2 == 0)
    return ((temp % m) * temp);
  else
    return ((x * temp % m) * temp % m) % m;
}
long long inv(long long x) {
  return (power(x, 1000000007 - 2, 1000000007)) % 1000000007;
}
bool comp(long long a, long long b) { return a < b; }
long long DP[301][301];
int32_t main() {
  cin.tie(0), iostream::sync_with_stdio(0);
  long long T;
  cin >> T;
  while (T--) {
    long long n, m, NA = 0;
    cin >> n >> m;
    for (long long i = 0; i < n; i++)
      for (long long l = 0; l < m; l++) cin >> DP[i][l];
    for (long long i = 0; i < n; i++) {
      for (long long l = 0; l < m; l++) {
        long long base = 4;
        if ((!i) || (i + 1 == n)) base--;
        if (!l || (l + 1 == m)) base--;
        if (DP[i][l] <= base)
          DP[i][l] = base;
        else
          NA = 1;
      }
    }
    if (NA)
      cout << "NO" << '\n';
    else {
      cout << "YES" << '\n';
      for (long long i = 0; i < n; i++) {
        for (long long l = 0; l < m; l++) cout << DP[i][l] << ' ';
        cout << '\n';
      }
    }
  }
  return 0;
}
