#include <bits/stdc++.h>
using namespace std;
int a[1000][1000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) cin >> a[i][j];
    }
    bool bo = 1;
    for (int i = 1; i <= n && bo; ++i) {
      int x = 0;
      for (int j = 1; j <= m && bo; ++j) {
        if (a[i][j + 1] >= 0 && j + 1 <= m) ++x;
        if (a[i][j - 1] >= 0 && j - 1 >= 1) ++x;
        if (a[i + 1][j] >= 0 && i + 1 <= n) ++x;
        if (a[i - 1][j] >= 0 && i - 1 >= 1) ++x;
        if (a[i][j] <= x)
          a[i][j] = x, x = 0;
        else
          bo = 0;
      }
    }
    if (bo) {
      cout << "YES\n";
      for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) cout << a[i][j] << " ";
        cout << "\n";
      }
    } else
      cout << "NO\n";
  }
}
