#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
int X[4] = {1, 0, -1, 0};
int Y[4] = {0, 1, 0, -1};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--) {
    int n, m;
    cin >> n >> m;
    int mat[305][305];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> mat[i][j];
      }
    }
    int flag = 1, cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (mat[i][j]) {
          cnt = 0;
          for (int k = 0; k < 4; k++) {
            int tx = i + X[k];
            int ty = j + Y[k];
            if (tx >= 0 && tx < n && ty >= 0 && ty < m) {
              cnt++;
            }
          }
          if (mat[i][j] > cnt) {
            flag = 0;
            break;
          }
        }
      }
    }
    if (!flag)
      cout << "NO\n";
    else {
      for (int i = 0; i < m; i++) {
        if (i == 0 || i == m - 1) {
          mat[0][i] = 2;
          mat[n - 1][i] = 2;
        } else
          mat[0][i] = 3, mat[n - 1][i] = 3;
      }
      for (int i = 1; i < n - 1; i++) {
        for (int j = 0; j < m; j++) {
          if (j == 0 || j == m - 1)
            mat[i][j] = 3;
          else
            mat[i][j] = 4;
        }
      }
      cout << "YES" << endl;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) cout << mat[i][j] << ' ';
        cout << endl;
      }
    }
  }
}
