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