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