#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
bool isperfect(long long n) {
  long long y = sqrt(n);
  if (n % y == 0 && y * y == n) return true;
  return false;
}
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) return a.second > b.second;
  return a.first < b.first;
}
long long powi(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(long long n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
bool prime[10000000];
void seive() {
  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {
    if (prime[i]) continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long a[n][m];
    int f = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
        if ((i == 0 && j == 0) || (i == n - 1 && j == m - 1) ||
            (i == n - 1 && j == 0) || (i == 0 && j == m - 1)) {
          if (a[i][j] > 2) f = 1;
          continue;
        }
        if (i == 0 || j == 0 || i == n - 1 || j == m - 1) {
          if (a[i][j] > 3) {
            f = 1;
          }
        } else {
          if (a[i][j] > 4) {
            f = 1;
          }
        }
      }
    }
    if (f) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if ((i == 0 && j == 0) || (i == n - 1 && j == m - 1) ||
            (i == n - 1 && j == 0) || (i == 0 && j == m - 1)) {
          cout << 2 << " ";
          continue;
        }
        if (i == 0 || j == 0 || i == n - 1 || j == m - 1) {
          cout << 3 << " ";
        } else {
          cout << 4 << " ";
        }
      }
      cout << endl;
    }
  }
}
