#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
    int n, m;
    cin >> n >> m;

    vector <int> x(m), diff(m), got(m);
    for (int i = 0; i < m; i++) {
        cin >> x[i];
    }

    ll ans = 0;
    int cntpl = 0, cntmn = 0;
    for (int i = m - 1; i >= 0; i--) {
        diff[i] = cntpl - cntmn;

        //cout << diff[i] << ' ';

        if (cntpl - cntmn < n) {
            ans += x[i];
            cntpl++;
            got[i] = 1;

            //cout << 1 << ' ';

            continue;
        }
        int to = i;
        int mn = 1e9 + 5;
        for (int j = i + 1; j < m && diff[j] > 0; j++) {
            if (mn > x[j] && got[j]) {
                mn = x[j];
                to = j;
            }
        }

        if (to != i && mn < x[i]) {
            for (int j = i; j < to; j++) {
                //diff[j]--;
            }

            diff[to]--;

            //cout << 2 << ' ';
            ans -= 2 * x[to];
            ans += x[i];

            got[i] = 1;
            got[to] = 0;
        } else {
            ans -= x[i];
            cntmn++;

            //cout << 3 << ' ';
        }
    }
    
    cout << ans << '\n';
    for (int i = 0; i < m; i++) {
        cout << diff[i] << ' ';
    }

    cout << '\n';

    for (int i = 0; i < m ; i++) {
        cout << got[i] << ' ';
    }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t; cin >> t;
    
    while (t--) {
        solve();
    }
    
}

/*

*/