#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[301][301];
  int n, m;
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    bool p = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> arr[i][j];
        if (arr[i][j] > 4) {
          p = false;
        }
        if (i == 0 || i == n - 1) {
          if (arr[i][j] > 3) {
            p = false;
          }
        }
        if (j == 0 || j == m - 1) {
          if (arr[i][j] > 3) {
            p = false;
          }
        }
        if ((i == 0 && j == 0) || (i == n - 1 && j == 0) ||
            (i == 0 && j == m - 1) || (i == n - 1 && j == m - 1)) {
          if (arr[i][j] > 2) {
            p = false;
          }
        }
      }
    }
    if (p == false) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    cout << "2 ";
    for (int j = 1; j < m - 1; j++) {
      cout << "3 ";
    }
    cout << "2\n";
    for (int i = 1; i < n - 1; i++) {
      cout << "3 ";
      for (int j = 1; j < m - 1; j++) {
        cout << "4 ";
      }
      cout << "3\n";
    }
    cout << "2 ";
    for (int j = 1; j < m - 1; j++) {
      cout << "3 ";
    }
    cout << "2\n";
  }
  return 0;
}
