#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int a[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cin >> a[i][j];
    }
    int b[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        b[i][j] = 0;
        if (i - 1 >= 0) b[i][j]++;
        if (j - 1 >= 0) b[i][j]++;
        if (i + 1 < n) b[i][j]++;
        if (j + 1 < m) b[i][j]++;
      }
    }
    int yy = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (a[i][j] > b[i][j]) {
          yy = 1;
          break;
        }
      }
    }
    if (yy == 1)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) cout << b[i][j] << " ";
        cout << endl;
      }
    }
  }
  return 0;
}
