#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= f;
}
int t, n, m;
int mp[305][305];
int main() {
  cin >> t;
  while (t--) {
    memset(mp, 0, sizeof(mp));
    int f = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        cin >> mp[i][j];
        if (mp[i][j] == 3) {
          if ((i == 1 && j == 1) || (i == n && j == m) || (i == 1 && j == m) ||
              (i == n && j == 1))
            f = 1;
        }
        if (mp[i][j] == 4) {
          if (i == 1 || j == 1 || i == n || j == m) f = 1;
        }
        if (mp[i][j] > 4) f = 1;
      }
    if (f)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
          if ((i == 1 && j == 1) || (i == n && j == m) || (i == 1 && j == m) ||
              (i == n && j == 1))
            cout << 2 << " ";
          else if (i == 1 || j == 1 || i == n || j == m)
            cout << 3 << " ";
          else
            cout << 4 << " ";
        }
        cout << endl;
      }
    }
  }
  return 0;
}
