#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long SIZE = 100000;
const int INF = 0x3f3f3f3f;
const long long ll_INF = 0x3f3f3f3f3f3f3f3f;
const long double PI = acos(-1);
const long long MAXN = numeric_limits<long long>::max();
const long long MAX = 2000000;
bool sortinrev(const pair<long long, string> &a,
               const pair<long long, string> &b) {
  return (a.first > b.first);
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
bool isprime(long long n) {
  if (n <= 1) return false;
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
vector<long long> prime;
long long a[MAX];
void SOE() {
  memset(a, 1, sizeof(a));
  for (long long i = 2; i * i <= MAX; i++) {
    if (a[i])
      for (long long j = i * i; j <= MAX; j += i) {
        a[j] = 0;
      }
  }
  for (long long i = 2; i < MAX; i++)
    if (a[i]) prime.push_back(i);
}
map<long long, long long> powers;
vector<long long> PrimeFactors(long long n) {
  vector<long long> v;
  if (n % 2 == 0) {
    v.push_back(2);
  }
  while (n % 2 == 0) {
    n = n / 2;
    powers[2]++;
  }
  for (long long i = 3; i <= sqrt(n); i++) {
    if (n % i == 0) v.push_back(i);
    while (n % i == 0) {
      n = n / i;
      powers[i]++;
    }
  }
  if (n > 2) {
    v.push_back(n);
    powers[n]++;
  }
  return v;
}
long long FastModExpo(long long x, long long y, long long m) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % m;
    }
    x = (x * x) % m;
    y = y >> 1;
  }
  return res;
}
long long diffbits(long long x, long long y) {
  long long a = x ^ y;
  long long ans = __builtin_popcountll(a);
  return ans;
}
long long vis[100001];
vector<long long> adj[100001];
void dfs(long long u) {
  vis[u] = 1;
  for (auto x : adj[u]) {
    if (vis[x] == 0) dfs(x);
  }
}
bool check(int **a, int row, int col) {
  if (a[0][0] > 2 || a[row - 1][0] > 2 || a[0][col - 1] > 2 ||
      a[row - 1][col - 1] > 2)
    return false;
  for (int i = 1; i < row - 1; i++) {
    if (a[i][0] > 3) return false;
  }
  for (int i = 1; i < row - 1; i++) {
    if (a[i][col - 1] > 3) return false;
  }
  for (int i = 1; i < col - 1; i++) {
    if (a[0][i] > 3) return false;
  }
  for (int i = 1; i < col - 1; i++) {
    if (a[row - 1][i] > 3) return false;
  }
  for (int i = 1; i < row - 1; i++) {
    for (int j = 1; j < col - 1; j++) {
      if (a[i][j] > 4) return false;
    }
  }
  return true;
}
void solve() {
  int row, col;
  cin >> row >> col;
  int **a = new int *[row];
  for (int i = 0; i < row; i++) {
    a[i] = new int[col];
    for (int j = 0; j < col; j++) {
      cin >> a[i][j];
    }
  }
  if (!check(a, row, col)) {
    cout << "NO" << endl;
  } else {
    a[0][0] = 2;
    a[0][col - 1] = 2;
    a[row - 1][0] = 2;
    a[row - 1][col - 1] = 2;
    for (int i = 1; i < row - 1; i++) {
      a[i][0] = 3;
    }
    for (int i = 1; i < row - 1; i++) {
      a[i][col - 1] = 3;
    }
    for (int i = 1; i < col - 1; i++) {
      a[0][i] = 3;
    }
    for (int i = 1; i < col - 1; i++) {
      a[row - 1][i] = 3;
    }
    for (int i = 1; i < row - 1; i++) {
      for (int j = 1; j < col - 1; j++) {
        a[i][j] = 4;
      }
    }
    cout << "YES" << endl;
    for (long long i = 0; i < row; i++) {
      for (long long j = 0; j < col; j++) {
        cout << a[i][j] << " ";
      }
      cout << endl;
    }
  }
  for (int i = 0; i < row; i++) {
    delete[] a[i];
  }
  delete[] a;
}
int main() {
  std::ios::sync_with_stdio(false);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
