#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int ans = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) ans = (ans << 3) + (ans << 1) + (c ^ 48);
  return ans * f;
}
inline int cmin(int &a, int b) { return a = min(a, b); }
inline int cmax(int &a, int b) { return a = max(a, b); }
int a[1005][1005], b[1005][1005];
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int main() {
  int T = read();
  while (T--) {
    int n = read(), m = read();
    int flag = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        a[i][j] = read();
        int cnt = 0;
        for (int k = 0; k < 4; k++) {
          int ii = i + dx[k], jj = j + dy[k];
          if (0 < ii && ii <= n && 0 < jj && jj <= m) cnt++;
        }
        if (cnt < a[i][j]) flag = 1;
        b[i][j] = cnt;
      }
    }
    if (flag) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) cout << b[i][j] << ' ';
      cout << endl;
    }
  }
  return 0;
}
