#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int i, n, m, j;
    int flag = 0;
    cin >> n >> m;
    long long int a[n][m];
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        cin >> a[i][j];
      }
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        int count = 0;
        if (i - 1 >= 0) count++;
        if (i + 1 < n) count++;
        if (j - 1 >= 0) count++;
        if (j + 1 < m) count++;
        if (a[i][j] > count) {
          flag = 1;
          break;
        }
        a[i][j] = count;
      }
      if (flag == 1) {
        break;
      }
    }
    if (flag == 1)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
          cout << a[i][j] << " ";
        }
        cout << endl;
      }
    }
  }
}
