Problem: Drazil likes heap very much. So he created a problem with heap:

There is a max heap with a height h implemented on the array. The details of this heap are the following:

This heap contains exactly 2^h - 1 distinct positive non-zero integers. All integers are distinct. These numbers are stored in the array a indexed from 1 to 2^h-1. For any 1 < i < 2^h, a[i] < a[\left ⌊{i/2}\right ⌋].

Now we want to reduce the height of this heap such that the height becomes g with exactly 2^g-1 numbers in heap. To reduce the height, we should perform the following action 2^h-2^g times:

Choose an index i, which contains an element and call the following function f in index i:

<image>

Note that we suppose that if a[i]=0, then index i don't contain an element.

After all operations, the remaining 2^g-1 element must be located in indices from 1 to 2^g-1. Now Drazil wonders what's the minimum possible sum of the remaining 2^g-1 elements. Please find this sum and find a sequence of the function calls to achieve this value.

Input

The first line of the input contains an integer t (1 ≤ t ≤ 70 000): the number of test cases.

Each test case contain two lines. The first line contains two integers h and g (1 ≤ g < h ≤ 20). The second line contains n = 2^h-1 distinct positive integers a[1], a[2], …, a[n] (1 ≤ a[i] < 2^{20}). For all i from 2 to 2^h - 1, a[i] < a[\left ⌊{i/2}\right ⌋].

The total sum of n is less than 2^{20}.

Output

For each test case, print two lines.

The first line should contain one integer denoting the minimum sum after reducing the height of heap to g. The second line should contain 2^h - 2^g integers v_1, v_2, …, v_{2^h-2^g}. In i-th operation f(v_i) should be called.

Example

Input


2
3 2
7 6 3 5 4 2 1
3 2
7 6 5 4 3 2 1


Output


10
3 2 3 1
8
2 1 3 1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int hashmodcnt = 2;
const int mod = 1000000007;
;
const int maxn = 3000010;
unsigned long long powmod(unsigned long long n, unsigned long long k,
                          unsigned long long _mod = mod) {
  unsigned long long ret = 1;
  while (k) {
    if (k & 1) ret = ret * n % _mod;
    n = n * n % _mod;
    k >>= 1;
  }
  return ret;
}
unsigned long long hashmi[hashmodcnt][maxn];
unsigned long long hashseed[hashmodcnt];
unsigned long long hashmod[hashmodcnt];
unsigned long long validseed[20] = {
    10007, 10009, 10037, 10039, 10061, 10067, 10069, 10079, 10091, 10093,
    10099, 10103, 10111, 10133, 10139, 10141, 10151, 10159, 10163, 10169};
unsigned long long validmod[20] = {
    1000000007, 1000000009, 1000000021, 1000000033, 1000000087,
    1000000093, 1000000097, 1000000103, 1000000123, 1000000181,
    1000000207, 1000000223, 1000000241, 1000000271, 1000000289,
    1000000297, 1000000321, 1000000349, 1000000363, 1000000403};
void InitTemplate() {
  srand(time(0));
  for (int i = 0; i < hashmodcnt; i++) {
    hashseed[i] = validseed[rand() % 20];
    hashmod[i] = validmod[rand() % 20];
    hashmi[i][0] = 1;
    for (int j = 1; j < maxn; j++)
      hashmi[i][j] = hashmi[i][j - 1] * hashseed[i] % hashmod[i];
  }
}
struct Hash {
  Hash() {
    memset(val, 0, sizeof(val));
    len = 0;
  }
  Hash(unsigned long long v) {
    len = 1;
    for (int i = 0; i < hashmodcnt; i++) val[i] = v % hashmod[i];
  }
  Hash(const vector<int>& vec) {
    Hash tmp;
    for (int i = 0; i < vec.size(); i++) tmp = tmp.append(vec[i]);
    *this = tmp;
  }
  Hash(const string& s) {
    Hash tmp;
    for (int i = 0; i < s.size(); i++) tmp = tmp.append(s[i]);
    *this = tmp;
  }
  void merge(const Hash& lc, const Hash& rc) {
    len = lc.len + rc.len;
    for (int i = 0; i < hashmodcnt; i++) {
      if (rc.len == 0)
        val[i] = lc.val[i];
      else
        val[i] = (lc.val[i] * hashmi[i][rc.len] + rc.val[i]) % hashmod[i];
    }
  }
  Hash append(unsigned long long v) const {
    Hash ret(*this);
    ret.len++;
    for (int i = 0; i < hashmodcnt; i++)
      ret.val[i] = (ret.val[i] * hashseed[i] + v) % hashmod[i];
    return ret;
  }
  Hash update(unsigned long long v) const { return append(v); }
  Hash upd(unsigned long long v) const { return append(v); }
  Hash operator+(const Hash& obj) const {
    Hash ret;
    ret.merge(*this, obj);
    return ret;
  }
  Hash operator-(const Hash& obj) const {
    Hash ret(*this);
    ret.len -= obj.len;
    for (int i = 0; i < hashmodcnt; i++)
      ret.val[i] = (ret.val[i] - obj.val[i] * hashmi[i][ret.len] % hashmod[i] +
                    hashmod[i]) %
                   hashmod[i];
    return ret;
  }
  bool operator<(const Hash& obj) const {
    if (len != obj.len) return len < obj.len;
    for (int i = 0; i < hashmodcnt; i++)
      if (val[i] - obj.val[i]) return val[i] < obj.val[i];
    return false;
  }
  bool operator==(const Hash& obj) const {
    if (len != obj.len) return false;
    for (int i = 0; i < hashmodcnt; i++)
      if (val[i] - obj.val[i]) return false;
    return true;
  }
  int len;
  unsigned long long val[hashmodcnt];
};
struct StaticClass {
  StaticClass() { InitTemplate(); }
};
static StaticClass _nonsence;
bool ok[maxn];
int val[maxn];
void setok(int pos, int n) {
  ok[0] = false;
  while (pos) {
    int lc = pos * 2;
    int rc = lc + 1;
    bool o = false;
    if (val[pos] == 0)
      o = false;
    else if (pos > n)
      o = true;
    else {
      if (val[lc] > val[rc])
        o = ok[lc];
      else
        o = ok[rc];
    }
    ok[pos] = o;
    pos /= 2;
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int h, g;
    scanf("%d%d", &h, &g);
    for (int i = 1; i <= (1 << (h + 1)); i++) ok[i] = false, val[i] = 0;
    int n = (1 << g) - 1;
    for (int i = 1; i < (1 << h); i++) scanf("%d", &val[i]);
    for (int i = (1 << h) - 1; i >= 1; i--) setok(i, n);
    vector<int> vec;
    int now = 1;
    for (int i = 1; i <= (1 << h) - (1 << g); i++) {
      while (!ok[now]) now++;
      int tmp = now;
      vec.push_back(tmp);
      while (true) {
        int lc = tmp * 2;
        int rc = lc + 1;
        if (!val[lc] && !val[rc]) {
          val[tmp] = 0;
          setok(tmp, n);
          break;
        }
        if (val[lc] > val[rc]) {
          val[tmp] = val[lc];
          tmp = lc;
        } else {
          val[tmp] = val[rc];
          tmp = rc;
        }
      }
    }
    long long sum = 0;
    for (int i = 1; i < (1 << g); i++) sum += val[i];
    printf("%lld\n", sum);
    for (int i = 0; i < vec.size(); i++) printf("%d ", vec[i]);
    puts("");
  }
}