#include <bits/stdc++.h>
using namespace std;
const int N = 1E5 + 10;
long long n, k, vis[N], times[N], vis2[N];
struct edge {
  int val, to;
  edge(int t, int w) { val = w, to = t; }
};
struct cmp {
  bool operator()(pair<long long, long long> a, pair<long long, long long> b) {
    return (a.first - a.first / 2) * a.second <
           (b.first - b.first / 2) * b.second;
  }
};
vector<edge> G[N];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               cmp>
    nums;
long long sum = 0;
void dfs(int x) {
  vis[x] = 1;
  if (G[x].size() == 1 && x > 1) {
    times[x] = 1;
    return;
  } else {
    for (auto i : G[x]) {
      if (!vis[i.to]) {
        dfs(i.to);
        vis[i.to] = 1;
        times[x] += times[i.to];
      }
    }
  }
  return;
}
void dfs2(int x) {
  vis2[x] = 1;
  if (G[x].size() == 1 && x > 1)
    return;
  else {
    for (auto e : G[x]) {
      if (!vis2[e.to]) {
        nums.push(make_pair(e.val, times[e.to]));
        sum += e.val * times[e.to];
        dfs2(e.to);
      }
    }
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  string str;
  while (t--) {
    cin >> n >> k;
    for (int i = 0; i <= n; i++)
      G[i].clear(), times[i] = 0, vis[i] = 0, vis2[i] = 0;
    sum = 0;
    while (!nums.empty()) nums.pop();
    for (int i = 0; i < n - 1; i++) {
      int u, v, w;
      cin >> u >> v >> w;
      G[u].emplace_back(v, w);
      G[v].emplace_back(u, w);
    }
    dfs(1);
    dfs2(1);
    long long cnt = 0;
    pair<long long, long long> mm;
    while (sum > k) {
      mm = nums.top();
      nums.pop();
      cnt++;
      sum -= (mm.first - mm.first / 2) * mm.second;
      nums.push(make_pair(mm.first / 2, mm.second));
    }
    cout << cnt << endl;
  }
  return 0;
}
