#include <bits/stdc++.h>
using namespace std;
int maps[305][305];
int main(int argc, const char* argv[]) {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> maps[i][j];
      }
    }
    bool flag = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (i == 0 || i == n - 1) {
          if (j == 0 || j == m - 1) {
            if (maps[i][j] > 2) {
              flag = false;
            }
            maps[i][j] = 2;
          } else {
            if (maps[i][j] > 3) {
              flag = false;
            }
            maps[i][j] = 3;
          }
        } else if (j == 0 || j == m - 1) {
          if (i == 0 || i == n - 1) {
            if (maps[i][j] > 2) {
              flag = false;
            }
            maps[i][j] = 2;
          } else {
            if (maps[i][j] > 3) {
              flag = false;
            }
            maps[i][j] = 3;
          }
        } else {
          if (maps[i][j] > 4) {
            flag = false;
          }
          maps[i][j] = 4;
        }
        if (!flag) {
          break;
        }
      }
      if (!flag) {
        break;
      }
    }
    if (!flag) {
      cout << "NO" << endl;
    } else {
      cout << "YES" << endl;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          cout << maps[i][j] << " ";
        }
        cout << endl;
      }
    }
  }
  return 0;
}
