#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;      void solve() {    int m, k;    cin >> m >> k;       vector<pii> a;       int ai;    for (int i = 1; i <= k; i++) {     cin >> ai;     a.push_back({ai, i});    }       sort(a.begin(), a.end(), greater<pii>());       int n = 1;    for (; ; n++) {     if (m > n * n - (n / 2) * (n / 2)) continue;     if (a[0].first > n * ((n + 1) / 2)) continue;     break;    }        vector<pii> pos[3];    for (int i = 0; i < n; i++) {     for (int j = 0; j < n; j++) {      int idx = ((i & 1) << 1) + (j & 1);      if (idx != 3)        pos[idx].push_back({i, j});     }    }       vector<vector<int>> ans(n, vector<int>(n, 0));       for (auto [cnt, val] : a) {     vector<pii> &curr = pos[1].empty() ? pos[2] : pos[1];        for (; !curr.empty() && cnt > 0; cnt--) {      auto [x, y] = curr.back();      curr.pop_back();      ans[x][y] = val;     }     for (; cnt > 0; cnt--) {      auto [x, y] = pos[0].back();      pos[0].pop_back();      ans[x][y] = val;     }    }       cout << n <<   n ;    for (int i = 0; i < n; i++) {     for (int j = 0; j < n; j++) {      cout << ans[i][j] <<    ;     }     cout <<   n ;    }   }      int main() {    ios_base::sync_with_stdio(0);    cin.tie(0);       int t;    cin >> t;       while (t--) {     solve();    }       return 0;   }   