#include <bits/stdc++.h>
using namespace std;
int32_t get_max_possible(int32_t i, int32_t j, int32_t height, int32_t width) {
  bool at_side_row = i == 0 || i == height - 1;
  bool at_side_col = j == 0 || j == width - 1;
  if (at_side_row && at_side_col) {
    return 2;
  } else if (at_side_row || at_side_col) {
    return 3;
  } else {
    return 4;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int32_t tests;
  cin >> tests;
  for (int32_t test = 0; test < tests; test++) {
    int32_t height, width;
    cin >> height >> width;
    bool valid = true;
    for (int32_t i = 0; i < height; i++) {
      for (int32_t j = 0; j < width; j++) {
        int32_t curr;
        cin >> curr;
        if (curr > get_max_possible(i, j, height, width)) {
          valid = false;
        }
      }
    }
    if (valid) {
      cout << "YES\n";
      for (int32_t i = 0; i < height; i++) {
        for (int32_t j = 0; j < width; j++) {
          cout << get_max_possible(i, j, height, width) << " ";
        }
        cout << "\n";
      }
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
