func_code_string: #include<bits/stdc++.h>   using namespace std;      #ifdef LOCAL   #include  debug.h    #endif      #ifdef LOCAL   #define debug(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__)   #else   #define debug(...) 42   #endif      #define endl   n    typedef long long ll;   typedef long double ld;   typedef vector<int> vi;   typedef std::vector<vector<int> > vvi;   typedef pair<int, int> pi;   typedef pair<ll, ll> pll;   typedef vector<ll> vll;   typedef vector<pi> vpi;   typedef vector<pll> vpll;   typedef vector<vll> vvll;   typedef vector<vi> vvi;   typedef vector<double> vd;   typedef vector<vector<double>> vvd;   typedef vector<ld> vld;   typedef vector<vld> vvld;   typedef vector<bool> vb;   typedef vector<vb> vvb;   typedef vector<char> vch;   typedef vector<vch> vvch;      #define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)   #define repi(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)   #define pb push_back   #define fi first   #define se second   #define all(a) a.begin(), a.end()   #define sz(a) (int)(a.size())      template<typename T> void umin(T &a, T b) { a = min(a, b); }   template<typename T> void umax(T &a, T b) { a = max(a, b); }      ll nxt() {    ll x; cin >> x; return x;   }      void setIO(string s) {    #ifndef LOCAL    ios_base::sync_with_stdio(0); cin.tie(0);     freopen((s+ .in ).c_str(), r ,stdin);    freopen((s+ .out ).c_str(), w ,stdout);    #endif   }      void yes() {    cout <<  yes n ;   }      void no() {    cout <<  no n ;   }      void flush() {    debug( ################# );   }      const ll mod = 1e9 + 7;   const ll INF = 1e9;      void solve() {     int m, k; cin >> m >> k;     vi cnt(k + 1);        rep(i, 1, k + 1) {       cnt[i] = nxt();     }        int mx = *max_element(all(cnt));     int mxid = -1;     rep(i, 1, k + 1) if (cnt[i] == mx) mxid = i;        int lo = 1, hi = 200005;     while (lo < hi) {       int mid = (lo + hi) / 2;       ll one = 1LL * mid * mid - 1LL * (mid / 2) * (mid / 2);       ll two = 1LL * mid * ((mid + 1) / 2);       if (one >= m && two >= mx) {         hi = mid;       } else {         lo = mid + 1;       }     }        int n = lo;     vvi a(n + 1, vi(n + 1));        vpi filling_order;     rep(i, 1, k + 1) filling_order.pb({cnt[i], i});     sort(all(filling_order)); reverse(all(filling_order));        vi order;     for (auto it : filling_order) {       rep(i, 0, it.fi) order.pb(it.se);     }        assert(sz(order) == m);     int ptr = 0;     int done = 0;     for (int row = 2; row <= n; row += 2) {       for (int col = 1; col <= n; col += 2) {         if (done >= mx) break;         a[row][col] = order[ptr++];         done++;       }     }        if (done < mx) {       for (int row = 1; row <= n; row += 2) {         for (int col = 1; col <= n; col += 2) {           if (done >= mx) break;           a[row][col] = order[ptr++];           done++;         }       }     } else {       for (int row = 2; row <= n; row += 2) for (int col = 1; col <= n; col += 2) {         if (ptr >= m) break;         if (a[row][col] == 0) a[row][col] = order[ptr++];       }     }     //all reds are filled        //fill all non-filled     for (int row = 1; row <= n; row++) {       int add = 2;       if (row % 2 == 1) {         add = 1;       }       for (int col = 1; col <= n; col += add) {         if (a[row][col] == 0 && ptr < m) {           a[row][col] = order[ptr++];         }       }     }        cout << n << endl;     for (int row = 1; row <= n; row++) {       for (int col = 1; col <= n; col++) {         cout << a[row][col] <<    ;       }       cout << endl;     }        flush();     for (int row = 1; row <= n; row++) for (int col = 1; col <= n; col++) {       debug(row, col);       if (row + 1 <= n && col + 1 <= n && a[row][col] != 0 && a[row + 1][col + 1] != 0) assert(a[row][col] != a[row + 1][col + 1]);       if (row + 1 <= n && col - 1 >= 1 && a[row][col] != 0 && a[row + 1][col - 1] != 0) assert(a[row][col] != a[row + 1][col - 1]);          if (row + 1 <= n && col + 1 <= n) assert(a[row][col] == 0 or a[row][col + 1] == 0 or a[row + 1][col] == 0 or a[row + 1][col + 1] == 0);     }   }           int32_t main(){    // setIO( trapped );    ios_base::sync_with_stdio(false);    cin.tie(NULL);       cout << fixed << setprecision(10);       int T = 1;    cin >> T;       for (int tc = 1; tc <= T; tc++) {     // cout <<  Case #  << tc <<  :  ;     solve();    }   }   