#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int t;   int main() {     cin >> t;     while (t--) {       int n, m;       bool nope = false;       cin >> n >> m;       for (int i = 0; i != n; i++) {         for (int j = 0; j != m; j++) {           ll a;           cin >> a;           if ((a > 4 && 0 < j < m - 1 && 0 < i < n - 1) || (a > 3 && j == 0) ||               (a > 3 && j == m - 1) || (a > 3 && i == 0) ||               (a > 3 && i == n - 1) || (a > 2 && j == 0 && i == 0) ||               (a > 2 && j == 0 && i == n - 1) ||               (a > 2 && j == m - 1 && i == n - 1) ||               (a > 2 && j == m - 1 && i == 0)) {             nope = true;           }         }       }       if (nope) cout <<  NO  << endl;       if (!nope) {         cout <<  YES n ;         for (int i = 0; i != n; i++) {           for (int j = 0; j != m; j++) {             if ((i == 0 && j == 0) || (i == 0 && j == m - 1) ||                 (i == n - 1 && j == 0) || (i == n - 1 && j == m - 1)) {               cout << 2 <<    ;             } else if ((0 < i < n - 1 && j == 0) ||                        (0 < i < n - 1 && j == m - 1) ||                        (i == 0 && 0 < j < m - 1) ||                        (i == n - 1 && 0 < j < m - 1)) {               cout << 3 <<    ;             } else {               cout << 4 <<    ;             }           }           cout <<   n ;         }       }     }     return 0;   }   