#include <bits/stdc++.h>
using namespace std;
const int INF = 1E9;
const int MOD = 1E9 + 7;
const int N = 1E7 + 5;
int t = 1;
int n, h[N], g, height, avail[N], ans[N];
long long a[N];
void Level(int u, int d) {
  h[u] = d;
  if (d == 20) return;
  Level(u * 2, d + 1);
  Level(u * 2 + 1, d + 1);
}
void F(int id) {
  while ((avail[id * 2] == 1 && avail[id * 2 + 1] == 1) == 0) {
    if (a[id * 2] > a[id * 2 + 1]) {
      a[id] = a[id * 2];
      id = id * 2;
    } else {
      a[id] = a[id * 2 + 1];
      id = id * 2 + 1;
    }
  }
  a[id] = 0;
  avail[id] = 1;
}
bool check(int id) {
  if (avail[id] == 1) return false;
  while ((avail[id * 2] == 1 && avail[id * 2 + 1] == 1) == 0) {
    if (a[id * 2] > a[id * 2 + 1])
      id = id * 2;
    else
      id = id * 2 + 1;
  }
  return h[id] > g;
}
void Input() {
  cin >> height >> g;
  n = (1 << height) - 1;
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
}
void Prepare() {}
void Solve() {
  long long Sum = 0;
  for (int i = 1; i <= 2 * n + 1; i++) avail[i] = 1;
  for (int i = 1; i <= n; i++) {
    Sum += a[i];
    avail[i] = 0;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (avail[i] == 0) {
      while (check(i)) {
        cnt++;
        ans[cnt] = i;
        Sum -= a[i];
        F(i);
      }
    }
  printf("%lld\n", Sum);
  for (int i = 1; i <= cnt; i++) printf("%d ", ans[i]);
  cout << "\n";
}
int main() {
  if (fopen("test"
            ".inp",
            "r")) {
    freopen(
        "test"
        ".inp",
        "r", stdin);
    freopen(
        "test"
        ".out",
        "w", stdout);
  };
  Level(1, 1);
  cin >> t;
  while (t--) {
    Input();
    Prepare();
    Solve();
  }
}
