#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int a[500][500];
    int f = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
        if (i > 0 && i < n - 1 && j > 0 && j < m - 1 && a[i][j] > 4)
          f = 0;
        else if ((i == 0 || j == 0 || i == n - 1 || j == m - 1) && a[i][j] > 3)
          f = 0;
      }
    }
    if (a[0][0] > 2 || a[n - 1][m - 1] > 2 || a[0][m - 1] > 2 ||
        a[n - 1][0] > 2)
      f = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) a[i][j] = 3;
    }
    for (int i = 1; i < n - 1; i++) {
      for (int j = 1; j < m - 1; j++) a[i][j] = 4;
    }
    a[0][0] = 2;
    a[0][m - 1] = 2;
    a[n - 1][0] = 2;
    a[n - 1][m - 1] = 2;
    if (f) {
      cout << "YES"
           << "\n";
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) cout << a[i][j] << " ";
        cout << "\n";
      }
    } else {
      cout << "NO"
           << "\n";
    }
  }
  return 0;
}
