#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1 << 21;
int a[MaxN];
int len;
int ans[MaxN];
void real_delete(int index) {
  while (true) {
    int left = index + index;
    int right = index + index + 1;
    if (a[left] == 0 && a[right] == 0) {
      a[index] = 0;
      return;
    }
    if (a[left] > a[right]) {
      a[index] = a[left];
      index = left;
    } else {
      a[index] = a[right];
      index = right;
    }
  }
}
int try_delete(int index) {
  int left = index + index;
  int right = left + 1;
  while (a[left] != 0 || a[right] != 0) {
    if (a[left] > a[right]) {
      index = left;
    } else {
      index = right;
    }
    left = index + index;
    right = left + 1;
  }
  return index;
}
void solve() {
  int h, g;
  scanf("%d %d", &h, &g);
  h = (1 << h) - 1;
  g = (1 << g) - 1;
  for (int i = 1; i <= h; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = h + 1; i <= h + h + 1; ++i) {
    a[i] = 0;
  }
  len = 0;
  for (int i = 1; i <= h; ++i) {
    while (a[i] > 0 && try_delete(i) > g) {
      ans[len] = i;
      len += 1;
      real_delete(i);
    }
  }
  long long sum = 0;
  for (int i = 1; i <= g; ++i) {
    sum = sum + (long long)a[i];
  }
  printf("%lld\n", sum);
  printf("%d", ans[0]);
  for (int i = 1; i < len; ++i) {
    printf(" %d", ans[i]);
  }
  printf("\n");
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    solve();
  }
  return 0;
}
