#include <bits/stdc++.h>
const int N = 100005;
const long double pi = 3.141592653;
const long long int MOD = 1000000007;
using namespace std;
int dx[9] = {1, -1, 0, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 0, 1, -1, 1, -1, 1, -1, 0};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, m, i, j, grid[305][305], f = 1;
    cin >> n >> m;
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= m; j++) {
        cin >> grid[i][j];
        if (i == 1 && j == 1 && grid[i][j] > 2)
          f = 0;
        else if (i == 1 && j == m && grid[i][j] > 2)
          f = 0;
        else if (i == n && j == 1 && grid[i][j] > 2)
          f = 0;
        else if (i == n && j == m && grid[i][j] > 2)
          f = 0;
        else if ((i == 1 || i == n) && (j != 1 && j != m) && grid[i][j] > 3)
          f = 0;
        else if ((j == 1 || j == m) && (i != 1 && i != n) && grid[i][j] > 3)
          f = 0;
        else if (grid[i][j] > 4)
          f = 0;
      }
    }
    if (f == 0)
      cout << "NO\n";
    else {
      for (i = 1; i <= n; i++) {
        for (j = 1; j <= m; j++) {
          if (i == 1 && j == 1)
            grid[i][j] = 2;
          else if (i == n && j == 1)
            grid[i][j] = 2;
          else if (i == 1 && j == m)
            grid[i][j] = 2;
          else if (i == n && j == m)
            grid[i][j] = 2;
          else if ((i == 1 || i == n) && (j != 1 && j != m))
            grid[i][j] = 3;
          else if ((j == 1 || j == m) && (i != 1 && i != n))
            grid[i][j] = 3;
          else
            grid[i][j] = 4;
        }
      }
      cout << "YES\n";
      for (i = 1; i <= n; i++) {
        for (j = 1; j <= m; j++) cout << grid[i][j] << " ";
        cout << "\n";
      }
    }
  }
  return 0;
}
