#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int data[n][m];
    bool ok = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> data[i][j];
        int num = 4;
        if (i == 0 || i == n - 1) {
          num--;
        }
        if (j == 0 || j == m - 1) {
          num--;
        }
        if (data[i][j] > num) {
          ok = false;
        }
        data[i][j] = num;
      }
    }
    if (ok) {
      cout << "YES" << endl;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          cout << data[i][j] << " ";
        }
        cout << endl;
      }
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
