#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  long long int n, m;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    long long int a[n][m];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) cin >> a[i][j];
    bool valid = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int val = 0;
        if (i > 0) val++;
        if (i < n - 1) val++;
        if (j > 0) val++;
        if (j < m - 1) val++;
        if (a[i][j] > val) {
          valid = false;
          break;
        }
        a[i][j] = val;
      }
    }
    if (valid) {
      cout << "YES" << endl;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) cout << a[i][j] << " ";
        cout << endl;
      }
    } else
      cout << "NO" << endl;
  }
}
