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>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long int M = 1000000007;
long long int inv(long long int a, long long int b) {
  return 1 < a ? b - inv(b % a, a) * b / a : 1;
}
long long int gcd(long long int x, long long int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
pair<long long int, long long int> neigh[4] = {
    {-1, 0}, {1, 0}, {0, 1}, {0, -1}};
long long int a[2100000];
long long int loc[2100000];
long long int n;
long long int lower;
vector<long long int> insert(vector<long long int> &a,
                             vector<long long int> &b) {
  vector<long long int> c(a.size() + b.size());
  long long int c1 = 0, c2 = 0, c3 = 0;
  while (c1 < a.size() && c2 < b.size()) {
    if (a[c1] < b[c2])
      c[c3++] = a[c1++];
    else
      c[c3++] = b[c2++];
  }
  while (c1 < a.size()) c[c3++] = a[c1++];
  while (c2 < b.size()) c[c3++] = b[c2++];
  return c;
}
pair<vector<long long int>, vector<long long int> > solve(long long int i) {
  vector<long long int> v;
  v.push_back(a[i]);
  if (i * 2 + 1 >= n) {
    return {vector<long long int>(), v};
  }
  auto one = solve(i * 2 + 1);
  auto two = solve(i * 2 + 2);
  vector<long long int> m1 = one.first;
  vector<long long int> m2 = two.first;
  vector<long long int> s1 = one.second;
  vector<long long int> s2 = two.second;
  if (i >= lower) {
    m1 = insert(m1, m2);
    s1 = insert(s1, s2);
    s1 = insert(s1, v);
    while (s1.size() > 1) {
      vector<long long int> tmp;
      tmp.push_back(s1[s1.size() - 1]);
      m1 = insert(m1, tmp);
      s1.erase(prev(s1.end()));
    }
    return {m1, s1};
  }
  long long int largest1 = *prev(s1.end());
  long long int largest2 = *prev(s2.end());
  auto nex1 = lower_bound(m1.begin(), m1.end(), largest2);
  auto nex2 = lower_bound(m2.begin(), m2.end(), largest1);
  bool e1 = nex1 == m1.end();
  bool e2 = nex2 == m2.end();
  long long int val1 = LLONG_MAX;
  if (!e1) val1 = *nex1;
  if (val1 < largest1) val1 = *lower_bound(m1.begin(), m1.end(), largest1);
  long long int val2 = LLONG_MAX;
  if (!e2) val2 = *nex2;
  if (val2 < largest2) val2 = *lower_bound(m2.begin(), m2.end(), largest2);
  m1 = insert(m1, m2);
  s1 = insert(s1, s2);
  if (val2 < val1) {
    m1.erase(lower_bound(m1.begin(), m1.end(), val2));
    vector<long long int> tmp;
    tmp.push_back(val2);
    s1 = insert(s1, tmp);
  } else {
    m1.erase(lower_bound(m1.begin(), m1.end(), val1));
    vector<long long int> tmp;
    tmp.push_back(val1);
    s1 = insert(s1, tmp);
  }
  m1 = insert(m1, v);
  return {m1, s1};
}
void prod(long long int i) {
  long long int left = 2 * i + 1;
  long long int right = 2 * i + 2;
  if (a[left] == 0 && a[right] == 0)
    a[i] = 0;
  else {
    if (a[left] > a[right]) {
      a[i] = a[left];
      loc[a[left]] = i;
      prod(left);
    } else {
      a[i] = a[right];
      loc[a[right]] = i;
      prod(right);
    }
  }
}
long long int pow2[2100000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  pow2[0] = 1;
  for (long long int i = 1; i < (23); i++) {
    pow2[i] = pow2[i - 1] * 2;
  }
  long long int _t;
  cin >> _t;
  for (long long int _t1 = 0; _t1 < (_t); _t1++) {
    long long int h;
    cin >> h;
    long long int g;
    cin >> g;
    n = pow2[h] - 1;
    lower = pow2[g - 1] - 1;
    for (long long int i = 0; i < (n); i++) cin >> a[i], loc[a[i]] = i;
    for (long long int i = n; i < (2 * n + 1); i++) a[i] = 0;
    vector<long long int> res;
    long long int sum = 0;
    auto ret = solve(0);
    vector<long long int> free = ret.first;
    vector<long long int> used = ret.second;
    for (long long int i = 0; i < (used.size()); i++) sum += used[i];
    for (long long int i = 0; i < (free.size()); i++) {
      long long int u = free[i];
      res.push_back(loc[u] + 1);
      prod(loc[u]);
    }
    cout << sum << endl;
    for (long long int _i = 0; _i < (res.size()); _i++)
      cout << (res)[_i] << " ";
    cout << endl;
  }
}