#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, h, g, n;
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld %lld", &h, &g);
    n = 1ll << h;
    pair<long long, long long> p[n - 1];
    for (long long i = 1; i < n; i++)
      scanf("%lld", &p[i - 1].first), p[i - 1].second = i;
    sort(p, p + n - 1);
    bool f[n * 2], ans[n];
    for (long long i = 1; i < n; i++) {
      if (i < (1ll << g))
        f[i] = true;
      else
        f[i] = false;
      ans[i] = false;
    }
    long long s = 0;
    for (auto e : p) {
      long long c = e.second;
      while (c > 0) {
        if (f[c] && !f[c * 2] && !f[c * 2 + 1]) {
          ans[e.second] = true, f[c] = false, s += e.first;
          break;
        }
        c /= 2;
      }
    }
    printf("%lld\n", s);
    for (long long i = n - 1; i > 0; i--)
      if (!ans[i]) printf("%lld ", i);
    printf("\n");
  }
}
