#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[307][307];
inline bool check(const int& i, const int& j) {
  return i >= 0 && i < n && j >= 0 && j < m;
}
int cnt_neighbors(const int& i, const int& j) {
  int res = 0;
  if (check(i - 1, j)) res++;
  if (check(i, j + 1)) res++;
  if (check(i + 1, j)) res++;
  if (check(i, j - 1)) res++;
  return res;
}
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
    bool flag = 1;
    for (int i = 0; i < n && flag; i++)
      for (int j = 0; j < m && flag; j++) {
        int tmp = cnt_neighbors(i, j);
        if (a[i][j] > tmp)
          flag = 0;
        else
          a[i][j] = tmp;
      }
    if (flag) {
      puts("YES");
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) printf("%d ", a[i][j]);
        puts("");
      }
    } else
      puts("NO");
  }
  return 0;
}
