#include <bits/stdc++.h>
using namespace std;
int get_i() {
  char c = getchar();
  bool neg = false;
  for (; c < '0' || '9' < c; c = getchar())
    if (c == '-') neg = true;
  int rs = c - '0';
  c = getchar();
  for (; '0' <= c && c <= '9'; c = getchar())
    rs = (rs << 1) + (rs << 3) + (c - '0');
  if (neg) rs = -rs;
  return rs;
}
void print_i(int _n) {
  bool neg = false;
  if (_n < 0) {
    neg = true;
    _n = -_n;
  }
  if (neg) putchar('-');
  int N = _n, rev, count = 0;
  rev = N;
  if (N == 0) {
    putchar('0');
    return;
  }
  while ((rev % 10) == 0) {
    count++;
    rev /= 10;
  }
  rev = 0;
  while (N != 0) {
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) {
    putchar(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar('0');
}
void print_l(long long _n) {
  long long N = _n, rev, count = 0;
  rev = N;
  if (N == 0) {
    putchar('0');
    return;
  }
  while ((rev % 10) == 0) {
    count++;
    rev /= 10;
  }
  rev = 0;
  while (N != 0) {
    rev = rev * 10ll + N % 10;
    N /= 10;
  }
  while (rev != 0) {
    putchar(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar('0');
}
void solve() {
  int h = get_i(), g = get_i();
  int n = (1 << h) - 1, fin = (1 << g) - 1;
  vector<pair<int, int> > pos;
  for (int i = 1, x; i <= n; i++) {
    x = get_i();
    pos.push_back({x, i});
  }
  sort(pos.begin(), pos.end());
  vector<bool> gotten(n + 1), taken(n + 1);
  long long ans = 0ll;
  for (int i = 0; i < pos.size(); i++) {
    int val = pos[i].first, id = pos[i].second;
    while (id > fin || gotten[id]) id /= 2;
    if (id == 0) continue;
    if (gotten[id * 2] == gotten[id * 2 + 1]) {
      gotten[id] = 1;
      taken[pos[i].second] = 1;
      ans += (long long)val;
    }
  }
  print_l(ans);
  putchar('\n');
  for (int i = n; i >= 1; i--) {
    if (!taken[i]) {
      print_i(i);
      putchar(' ');
    }
  }
  putchar('\n');
}
int main() {
  int t = get_i();
  while (t--) solve();
  return 0;
}
