#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 20;
int main() {
  int n, filas, columnas;
  cin >> n;
  while (n--) {
    cin >> filas >> columnas;
    int arr[300][300] = {0};
    bool ya = false;
    for (int i = 0; i < filas; i++) {
      for (int j = 0; j < columnas; j++) {
        cin >> arr[i][j];
        if (arr[i][j] > 4)
          ya = true;
        else if ((i == 0 && j == 0) || (i == 0 && j == columnas - 1) ||
                 (i == filas - 1 && j == 0) ||
                 (i == filas - 1 && j == columnas - 1)) {
          if (arr[i][j] > 2) ya = true;
        } else if (i == 0 || i == filas - 1 || j == 0 || j == columnas - 1) {
          if (arr[i][j] > 3) ya = true;
        }
      }
    }
    if (ya)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      for (int i = 0; i < filas; i++) {
        for (int j = 0; j < columnas; j++) {
          if ((i == 0 && j == 0) || (i == 0 && j == columnas - 1) ||
              (i == filas - 1 && j == 0) ||
              (i == filas - 1 && j == columnas - 1))
            cout << 2 << " ";
          else if (i == 0 || i == filas - 1 || j == 0 || j == columnas - 1)
            cout << 3 << " ";
          else
            cout << 4 << " ";
        }
        cout << endl;
      }
    }
  }
}
