#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int t, h, g;     cin >> t;     while (t--) {       scanf( %d %d , &h, &g);       int n = (1 << h) - 1, m = (1 << g) - 1;       std::vector<pair<int, int> > a(1 << h);       for (int i = 0; i < n; i++) {         scanf( %d , &a[i].first);         a[i].second = i + 1;       }       sort(a.begin(), a.end());       std::vector<int> notFree(n + 1, 0), taken(n + 1, 0);       ll ans = 0LL;       for (int i = 0; i < n; i++) {         int where = a[i].second;         while (where > m or notFree[where]) where = where >> 1;         if (!where) continue;         if (notFree[where << 1] == notFree[where << 1 | 1]) {           notFree[where] = 1;           ans += a[i].first;           taken[a[i].second] = 1;         }       }       printf( %lld n , ans);       for (int i = n; i >= 1; i--) {         if (!taken[i]) printf( %d  , i);         ;       }       puts(  );     }     return 0;   }   