#include <bits/stdc++.h>
using namespace std;
int neighbours(int el_i, int el_j, int mat_i, int mat_j) {
  int count{2};
  mat_i--;
  mat_j--;
  if ((el_j % mat_j) != 0 || (el_i % mat_i) != 0) count++;
  if ((el_j % mat_j) != 0 && (el_i % mat_i) != 0) count++;
  return count;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n, m;
    cin >> n >> m;
    bool isValid = true;
    int** A = new int*[n];
    for (int i = 0; i < n; i++) A[i] = new int[m];
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        cin >> A[i][j];
        if (A[i][j] > neighbours(i, j, n, m)) isValid = false;
      }
    if (!isValid) {
      cout << "NO\n";
      continue;
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        A[i][j] = neighbours(i, j, n, m);
      }
    cout << "YES\n";
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) cout << A[i][j] << " ";
      cout << endl;
    }
  }
  return 0;
}
