#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;
typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;
const int maxN = int(3e5)+7;
const int maxK = 51;
const ll inf = ll(1e18)+7;
int n , k , c[maxN];
vector<ii> g[maxN];
ll dp[maxN][maxK] , DP[maxN] , tmp[maxK];
pair<ii , ii> trace[maxN][maxK];
pair<ii , ii> base = {{-1 , -1} , {-1 , -1}};
int in[maxN] , sz[maxN] , DfsTime = 0 , pre[maxN];
void dfs_size(int u , int par){
in[u] = ++DfsTime;
for (auto e : g[u]){
int v = e.fi;
if (v != par){
sz[u]++;
dfs_size(v , u);
}
}
pre[in[u]] = sz[u];
}
void init(){
for (int i = 1 ; i <= n ; i++){
pre[i] += pre[i - 1];
}
}
int get(int u , int cnt){
int x = pre[in[u] - 1] + cnt + 1;
return x;
}
ii sigma[maxN];
void dfs(int u , int par){
for (auto e : g[u]){
int v = e.fi;
if (v == par) continue;
dfs(v , u);
}
int cnt = 0;
for (auto e : g[u]){
int v = e.fi;
int w = e.se;
if (v == par) continue;
int idx = get(u , cnt); cnt++;
for (int x = 0 ; x <= k ; x++) tmp[x] = -inf;
//min(x , y + w) == y + w
for (int y = 0 ; y + w <= k ; y++){
int x = max(k - (y + w) , y + w);
if (tmp[y + w] < dp[u][x] + dp[v][y]){
tmp[y + w] = dp[u][x] + dp[v][y];
trace[idx][y + w] = {{u , x} , {v , y}};
}
}
//min(x , y + w) == x
for (int x = 0 ; x <= k ; x++){
int y = max(max(k - x , x) - w , 0);
if (tmp[x] < dp[u][x] + dp[v][y]){
tmp[x] = dp[u][x] + dp[v][y];
trace[idx][x] = {{u , x} , {v , y}};
}
}
//
for (int x = 0 ; x <= k ; x++){
if (dp[u][x] > tmp[x]){
trace[idx][x] = {{u , x} , {-1 , -1}};
}
else{
dp[u][x] = tmp[x];
}
if (x >= w && dp[u][x] < dp[v][x - w]){
dp[u][x] = dp[v][x - w];
trace[idx][x] = {{-1 , -1} , {v , x - w}};
}
}
for (int x = k - 1 ; x >= 0 ; x--){
if (dp[u][x] < dp[u][x + 1]){
trace[idx][x] = {{u , x + 1} , {-1 , -1}};
dp[u][x] = dp[u][x + 1];
}
}
}
if (dp[u][0] < 1ll * c[u]){
dp[u][0] = 1ll * c[u];
if (sz[u] > 0){
trace[get(u , sz[u] - 1)][0] = base;
}
}
sigma[u] = {-1 , -1};
for (auto e : g[u]){
int v = e.fi;
int w = e.se;
if (v == par) continue;
if (DP[u] < DP[v]){
DP[u] = DP[v];
sigma[u] = {-1 , -1};
}
if (DP[u] < dp[v][k - w] + 1ll * c[u]){
DP[u] = dp[v][k - w] + 1ll * c[u];
sigma[u] = {v , k - w};
}
}
}
vector<int> res;
void find_path(int u , int x , int cnt){
if (cnt < 0){
res.push_back(u);
return;
}
auto it = trace[get(u , cnt)][x];
if (it == base){
res.push_back(u);
return;
}
int v = it.se.fi;
int y = it.se.se;
if (v != -1){
find_path(v , y , sz[v] - 1);
}
int nxt_u = it.fi.fi;
int nxt_x = it.fi.se;
if (nxt_u == -1) return;
if (v != -1){
find_path(nxt_u , nxt_x , cnt - 1);
}
else{
if (nxt_x == x + 1){
find_path(nxt_u , nxt_x , cnt);
}
else{
find_path(nxt_u , nxt_x , cnt - 1);
}
}
}
void solve(){
cin >> n >> k;
for (int i = 1 ; i <= n ; i++){
for (int x = 0 ; x <= k ; x++) dp[i][x] = -inf , trace[i][x] = base;
}
for (int i = 1 ; i <= n ; i++) cin >> c[i];
for (int i = 1 ; i < n ; i++){
int u , v , w;
cin >> u >> v >> w;
g[u].push_back({v , w});
g[v].push_back({u , w});
}
dfs_size(1 , 0);
init();
dfs(1 , 0);
if (dp[1][0] >= DP[1]){
find_path(1 , 0 , sz[1] - 1);
}
else{
for (int i = 1 ; i <= n ; i++){
if (DP[1] == DP[i] && sigma[i].fi != -1){
int u = sigma[i].fi;
int x = sigma[i].se;
res.push_back(i);
find_path(u , x , sz[u] - 1);
break;
}
}
}
cout << max(dp[1][0] , DP[1]) << "\n";
cout << sz(res) << "\n";
for (int x : res) cout << x << " ";
}
#define name "cay"
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(name".INP" , "r")){
freopen(name".INP" , "r" , stdin);
freopen(name".OUT" , "w" , stdout);
}
int t = 1; cin >> t;
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBhbGwodikgdi5iZWdpbigpICwgdi5lbmQoKQojZGVmaW5lIHN6KHYpIGludCh2LnNpemUoKSkKI2RlZmluZSB1bnEodikgc29ydChhbGwodikpOyB2LnJlc2l6ZSh1bmlxdWUoYWxsKHYpKSAtIHYuYmVnaW4oKSk7CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiBwYWlyPGludCAsIGludD4gaWk7CnR5cGVkZWYgcGFpcjxsb25nIGxvbmcgLCBpbnQ+IGxsaTsKCmNvbnN0IGludCBtYXhOID0gaW50KDNlNSkrNzsKY29uc3QgaW50IG1heEsgPSA1MTsKY29uc3QgbGwgaW5mID0gbGwoMWUxOCkrNzsKCmludCBuICwgayAsIGNbbWF4Tl07CnZlY3RvcjxpaT4gZ1ttYXhOXTsKbGwgZHBbbWF4Tl1bbWF4S10gLCBEUFttYXhOXSAsIHRtcFttYXhLXTsKcGFpcjxpaSAsIGlpPiB0cmFjZVttYXhOXVttYXhLXTsKcGFpcjxpaSAsIGlpPiBiYXNlID0ge3stMSAsIC0xfSAsIHstMSAsIC0xfX07CmludCBpblttYXhOXSAsIHN6W21heE5dICwgRGZzVGltZSA9IDAgLCBwcmVbbWF4Tl07Cgp2b2lkIGRmc19zaXplKGludCB1ICwgaW50IHBhcil7CiAgICBpblt1XSA9ICsrRGZzVGltZTsKICAgIGZvciAoYXV0byBlIDogZ1t1XSl7CiAgICAgICAgaW50IHYgPSBlLmZpOwogICAgICAgIGlmICh2ICE9IHBhcil7CiAgICAgICAgICAgIHN6W3VdKys7CiAgICAgICAgICAgIGRmc19zaXplKHYgLCB1KTsKICAgICAgICB9CiAgICB9CiAgICBwcmVbaW5bdV1dID0gc3pbdV07Cn0KCnZvaWQgaW5pdCgpewogICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKyspewogICAgICAgIHByZVtpXSArPSBwcmVbaSAtIDFdOwogICAgfQp9CgppbnQgZ2V0KGludCB1ICwgaW50IGNudCl7CiAgICBpbnQgeCA9IHByZVtpblt1XSAtIDFdICsgY250ICsgMTsKICAgIHJldHVybiB4Owp9CgppaSBzaWdtYVttYXhOXTsKCnZvaWQgZGZzKGludCB1ICwgaW50IHBhcil7CiAgICBmb3IgKGF1dG8gZSA6IGdbdV0pewogICAgICAgIGludCB2ID0gZS5maTsKICAgICAgICBpZiAodiA9PSBwYXIpIGNvbnRpbnVlOwogICAgICAgIGRmcyh2ICwgdSk7CiAgICB9CiAgICBpbnQgY250ID0gMDsKICAgIGZvciAoYXV0byBlIDogZ1t1XSl7CiAgICAgICAgaW50IHYgPSBlLmZpOwogICAgICAgIGludCB3ID0gZS5zZTsKICAgICAgICBpZiAodiA9PSBwYXIpIGNvbnRpbnVlOwogICAgICAgIGludCBpZHggPSBnZXQodSAsIGNudCk7IGNudCsrOwogICAgICAgIGZvciAoaW50IHggPSAwIDsgeCA8PSBrIDsgeCsrKSB0bXBbeF0gPSAtaW5mOwogICAgICAgIC8vbWluKHggLCB5ICsgdykgPT0geSArIHcKICAgICAgICBmb3IgKGludCB5ID0gMCA7IHkgKyB3IDw9IGsgOyB5KyspewogICAgICAgICAgICBpbnQgeCA9IG1heChrIC0gKHkgKyB3KSAsIHkgKyB3KTsKICAgICAgICAgICAgaWYgKHRtcFt5ICsgd10gPCBkcFt1XVt4XSArIGRwW3ZdW3ldKXsKICAgICAgICAgICAgICAgIHRtcFt5ICsgd10gPSBkcFt1XVt4XSArIGRwW3ZdW3ldOwogICAgICAgICAgICAgICAgdHJhY2VbaWR4XVt5ICsgd10gPSB7e3UgLCB4fSAsIHt2ICwgeX19OwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIC8vbWluKHggLCB5ICsgdykgPT0geAogICAgICAgIGZvciAoaW50IHggPSAwIDsgeCA8PSBrIDsgeCsrKXsKICAgICAgICAgICAgaW50IHkgPSBtYXgobWF4KGsgLSB4ICwgeCkgLSB3ICwgMCk7CiAgICAgICAgICAgIGlmICh0bXBbeF0gPCBkcFt1XVt4XSArIGRwW3ZdW3ldKXsKICAgICAgICAgICAgICAgIHRtcFt4XSA9IGRwW3VdW3hdICsgZHBbdl1beV07CiAgICAgICAgICAgICAgICB0cmFjZVtpZHhdW3hdID0ge3t1ICwgeH0gLCB7diAsIHl9fTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAvLwogICAgICAgIGZvciAoaW50IHggPSAwIDsgeCA8PSBrIDsgeCsrKXsKICAgICAgICAgICAgaWYgKGRwW3VdW3hdID4gdG1wW3hdKXsKICAgICAgICAgICAgICAgIHRyYWNlW2lkeF1beF0gPSB7e3UgLCB4fSAsIHstMSAsIC0xfX07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgIGRwW3VdW3hdID0gdG1wW3hdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh4ID49IHcgJiYgZHBbdV1beF0gPCBkcFt2XVt4IC0gd10pewogICAgICAgICAgICAgICAgZHBbdV1beF0gPSBkcFt2XVt4IC0gd107CiAgICAgICAgICAgICAgICB0cmFjZVtpZHhdW3hdID0ge3stMSAsIC0xfSAsIHt2ICwgeCAtIHd9fTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmb3IgKGludCB4ID0gayAtIDEgOyB4ID49IDAgOyB4LS0pewogICAgICAgICAgICBpZiAoZHBbdV1beF0gPCBkcFt1XVt4ICsgMV0pewogICAgICAgICAgICAgICAgdHJhY2VbaWR4XVt4XSA9IHt7dSAsIHggKyAxfSAsIHstMSAsIC0xfX07CiAgICAgICAgICAgICAgICBkcFt1XVt4XSA9IGRwW3VdW3ggKyAxXTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGlmIChkcFt1XVswXSA8IDFsbCAqIGNbdV0pewogICAgICAgIGRwW3VdWzBdID0gMWxsICogY1t1XTsKICAgICAgICBpZiAoc3pbdV0gPiAwKXsKICAgICAgICAgICAgdHJhY2VbZ2V0KHUgLCBzelt1XSAtIDEpXVswXSA9IGJhc2U7CiAgICAgICAgfQogICAgfQogICAgc2lnbWFbdV0gPSB7LTEgLCAtMX07CiAgICBmb3IgKGF1dG8gZSA6IGdbdV0pewogICAgICAgIGludCB2ID0gZS5maTsKICAgICAgICBpbnQgdyA9IGUuc2U7CiAgICAgICAgaWYgKHYgPT0gcGFyKSBjb250aW51ZTsKICAgICAgICBpZiAoRFBbdV0gPCBEUFt2XSl7CiAgICAgICAgICAgIERQW3VdID0gRFBbdl07CiAgICAgICAgICAgIHNpZ21hW3VdID0gey0xICwgLTF9OwogICAgICAgIH0KICAgICAgICBpZiAoRFBbdV0gPCBkcFt2XVtrIC0gd10gKyAxbGwgKiBjW3VdKXsKICAgICAgICAgICAgRFBbdV0gPSBkcFt2XVtrIC0gd10gKyAxbGwgKiBjW3VdOwogICAgICAgICAgICBzaWdtYVt1XSA9IHt2ICwgayAtIHd9OwogICAgICAgIH0KICAgIH0KfQoKdmVjdG9yPGludD4gcmVzOwoKdm9pZCBmaW5kX3BhdGgoaW50IHUgLCBpbnQgeCAsIGludCBjbnQpewogICAgaWYgKGNudCA8IDApewogICAgICAgIHJlcy5wdXNoX2JhY2sodSk7CiAgICAgICAgcmV0dXJuOwogICAgfQogICAgYXV0byBpdCA9IHRyYWNlW2dldCh1ICwgY250KV1beF07CiAgICBpZiAoaXQgPT0gYmFzZSl7CiAgICAgICAgcmVzLnB1c2hfYmFjayh1KTsKICAgICAgICByZXR1cm47CiAgICB9CiAgICBpbnQgdiA9IGl0LnNlLmZpOwogICAgaW50IHkgPSBpdC5zZS5zZTsKICAgIGlmICh2ICE9IC0xKXsKICAgICAgICBmaW5kX3BhdGgodiAsIHkgLCBzelt2XSAtIDEpOwogICAgfQogICAgaW50IG54dF91ID0gaXQuZmkuZmk7CiAgICBpbnQgbnh0X3ggPSBpdC5maS5zZTsKICAgIGlmIChueHRfdSA9PSAtMSkgcmV0dXJuOwogICAgaWYgKHYgIT0gLTEpewogICAgICAgIGZpbmRfcGF0aChueHRfdSAsIG54dF94ICwgY250IC0gMSk7CiAgICB9CiAgICBlbHNlewogICAgICAgIGlmIChueHRfeCA9PSB4ICsgMSl7CiAgICAgICAgICAgIGZpbmRfcGF0aChueHRfdSAsIG54dF94ICwgY250KTsKICAgICAgICB9CiAgICAgICAgZWxzZXsKICAgICAgICAgICAgZmluZF9wYXRoKG54dF91ICwgbnh0X3ggLCBjbnQgLSAxKTsKICAgICAgICB9CiAgICB9Cn0KCnZvaWQgc29sdmUoKXsKICAgIGNpbiA+PiBuID4+IGs7CiAgICBmb3IgKGludCBpID0gMSA7IGkgPD0gbiA7IGkrKyl7CiAgICAgICAgZm9yIChpbnQgeCA9IDAgOyB4IDw9IGsgOyB4KyspIGRwW2ldW3hdID0gLWluZiAsIHRyYWNlW2ldW3hdID0gYmFzZTsKICAgIH0KICAgIGZvciAoaW50IGkgPSAxIDsgaSA8PSBuIDsgaSsrKSBjaW4gPj4gY1tpXTsKICAgIGZvciAoaW50IGkgPSAxIDsgaSA8IG4gOyBpKyspewogICAgICAgIGludCB1ICwgdiAsIHc7CiAgICAgICAgY2luID4+IHUgPj4gdiA+PiB3OwogICAgICAgIGdbdV0ucHVzaF9iYWNrKHt2ICwgd30pOwogICAgICAgIGdbdl0ucHVzaF9iYWNrKHt1ICwgd30pOwogICAgfQogICAgZGZzX3NpemUoMSAsIDApOwogICAgaW5pdCgpOwogICAgZGZzKDEgLCAwKTsKICAgIGlmIChkcFsxXVswXSA+PSBEUFsxXSl7CiAgICAgICAgZmluZF9wYXRoKDEgLCAwICwgc3pbMV0gLSAxKTsKICAgIH0KICAgIGVsc2V7CiAgICAgICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKyspewogICAgICAgICAgICBpZiAoRFBbMV0gPT0gRFBbaV0gJiYgc2lnbWFbaV0uZmkgIT0gLTEpewogICAgICAgICAgICAgICAgaW50IHUgPSBzaWdtYVtpXS5maTsKICAgICAgICAgICAgICAgIGludCB4ID0gc2lnbWFbaV0uc2U7CiAgICAgICAgICAgICAgICByZXMucHVzaF9iYWNrKGkpOwogICAgICAgICAgICAgICAgZmluZF9wYXRoKHUgLCB4ICwgc3pbdV0gLSAxKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgY291dCA8PCBtYXgoZHBbMV1bMF0gLCBEUFsxXSkgPDwgIlxuIjsKICAgIGNvdXQgPDwgc3oocmVzKSA8PCAiXG4iOwogICAgZm9yIChpbnQgeCA6IHJlcykgY291dCA8PCB4IDw8ICIgIjsKfQoKI2RlZmluZSBuYW1lICJjYXkiCgppbnQgbWFpbigpewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CiAgICBpZiAoZm9wZW4obmFtZSIuSU5QIiAsICJyIikpewogICAgICAgIGZyZW9wZW4obmFtZSIuSU5QIiAsICJyIiAsIHN0ZGluKTsKICAgICAgICBmcmVvcGVuKG5hbWUiLk9VVCIgLCAidyIgLCBzdGRvdXQpOwogICAgfQogICAgaW50IHQgPSAxOyBjaW4gPj4gdDsKICAgIHNvbHZlKCk7CiAgICByZXR1cm4gMDsKfQ==