#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int m, n;
    cin >> m >> n;
    int a[m][n];
    int b[m][n];
    bool possible = true;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        cin >> a[i][j];
        b[i][j] = 4 - (i == 0) - (i == m - 1) - (j == 0) - (j == n - 1);
        if (a[i][j] > b[i][j]) {
          possible = false;
        }
      }
    }
    if (possible) {
      cout << "YES\n";
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
          cout << b[i][j] << " ";
        }
        cout << "\n";
      }
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
