#include <bits/stdc++.h>
using namespace std;
vector<int> adjl;
int pos[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int arr[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cin >> arr[i][j];
    }
    int flag = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int nb = 0;
        for (auto x : pos) {
          int a = x[0];
          int b = x[1];
          if (i + a >= 0 && i + a < n && j + b >= 0 && j + b < m) {
            nb++;
          }
        }
        if (arr[i][j] > nb) {
          flag = 0;
          break;
        }
        arr[i][j] = nb;
      }
      if (!flag) break;
    }
    if (!flag) {
      cout << "NO" << endl;
      continue;
    }
    cout << "YES" << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << arr[i][j] << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
