#include <bits/stdc++.h>
using namespace std;
long long int n, m, t, a[302][302], vis[102][102];
vector<long long int> adj[100005];
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) cin >> a[i][j];
    bool yes = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        int ct = 0;
        if (i + 1 < n) ct++;
        if (i > 0) ct++;
        if (j > 0) ct++;
        if (j + 1 < m) ct++;
        if (a[i][j] <= ct)
          a[i][j] = ct;
        else
          yes = false;
      }
    }
    if (!yes)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) cout << a[i][j] << " ";
        cout << endl;
      }
    }
  }
  return (0);
}
