#include <bits/stdc++.h>
using namespace std;
const int mx = 302;
int a[mx][mx];
int b[mx][mx];
int n, m;
void print();
bool solve(int k, int i, int j);
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    bool ans = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int x;
        cin >> x;
        a[i][j] = x;
        if (!solve(x, i, j)) ans = false;
      }
    }
    if (ans) {
      cout << "YES" << endl;
      print();
    } else
      cout << "NO" << endl;
  }
  return 0;
}
void print() {
  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)
          b[i][j] = 2;
        else
          b[i][j] = 3;
      } else {
        if (j == 0 || j == m - 1)
          b[i][j] = 3;
        else
          b[i][j] = 4;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cout << b[i][j] << " ";
    cout << endl;
  }
}
bool solve(int k, int i, int j) {
  if (k > 4) return false;
  if (i == 0 || i == n - 1) {
    if (j == 0 || j == m - 1) {
      if (k > 2) return false;
    } else {
      if (k > 3) return false;
    }
  } else {
    if (j == 0 || j == m - 1) {
      if (k > 3) return false;
    }
  }
  return true;
}
