#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    bool b = false;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int s;
        cin >> s;
        if (s >= 5) {
          if (b == false) {
            cout << "No" << endl;
            b = true;
          }
        } else if (s == 4 && (i == 0 || i == n - 1 || j == 0 || j == m - 1)) {
          if (b == false) {
            cout << "No" << endl;
            b = true;
          }
        } else if (s == 3 &&
                   ((i == 0 && j == 0) || (i == n - 1 && j == m - 1) ||
                    (j == 0 && i == n - 1) || (j == m - 1 && i == 0))) {
          if (b == false) {
            cout << "No" << endl;
            b = true;
          }
        }
      }
    }
    if (b == false) {
      cout << "Yes" << endl;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if ((i == 0 && j == 0) || (i == n - 1 && j == m - 1) ||
              (j == 0 && i == n - 1) || (j == m - 1 && i == 0)) {
            cout << "2"
                 << " ";
          } else if (i == 0 || i == n - 1 || j == 0 || j == m - 1) {
            cout << "3"
                 << " ";
          } else {
            cout << "4"
                 << " ";
          }
        }
        cout << endl;
      }
    }
  }
  return 0;
}
