#include <bits/stdc++.h>
const int N = 310;
const long long inf = 0x3f3f3f3f;
using namespace std;
const long long mod = (long long)1e9 + 7;
int num[N][N];
int main() {
  int t;
  scanf("%d", &t);
  ;
  while (t--) {
    int n, m;
    scanf("%d", &n);
    ;
    scanf("%d", &m);
    ;
    int flag = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        scanf("%d", &num[i][j]);
        ;
        if (num[i][j] > 4) flag = 1;
        if (((i == 0 && j == 0) || (i == 0 && j == m - 1) ||
             (j == 0 && i == n - 1) || (j == m - 1 & i == n - 1)) &&
            num[i][j] > 2)
          flag = 1;
        else if ((i == 0 || j == 0 || i == n - 1 || j == m - 1) &&
                 num[i][j] > 3)
          flag = 1;
      }
    }
    if (flag) {
      cout << "NO" << endl;
    } else {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if ((i == 0 && j == 0) || (i == 0 && j == m - 1) ||
              (j == 0 && i == n - 1) || (j == m - 1 & i == n - 1))
            num[i][j] = 2;
          else if (i == 0 || j == 0 || i == n - 1 || j == m - 1)
            num[i][j] = 3;
          else
            num[i][j] = 4;
        }
      }
      cout << "YES" << endl;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          cout << num[i][j];
          if (j != m - 1) cout << " ";
        }
        cout << endl;
      }
    }
  }
  return 0;
}
