#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
vector<pair<long long, long long> > g[N];
long long cnt[N];
long long par[N];
void dfs(long long node, long long p = -1) {
  par[node] = p;
  bool leaf = true;
  for (auto x : g[node]) {
    if (x.first == p) continue;
    leaf = false;
    dfs(x.first, node);
    cnt[node] += cnt[x.first];
  }
  if (leaf) cnt[node] = 1;
}
void solve() {
  long long n, s;
  cin >> n >> s;
  long long u, v, w;
  for (long long i = 0; i < n - 1; i++) {
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  dfs(1);
  long long res = 0;
  priority_queue<pair<long long, pair<long long, long long> > > pq;
  long long sum = 0;
  for (long long i = 1; i <= n; i++) {
    for (auto x : g[i]) {
      if (par[x.first] != i) continue;
      long long use = cnt[x.first];
      sum += (use * x.second);
      pq.push({(x.second - x.second / 2) * use, {use, x.second}});
    }
  }
  while (sum > s) {
    auto x = pq.top();
    pq.pop();
    res++;
    sum -= x.first;
    x.second.second = x.second.second / 2;
    x.first = (x.second.second - x.second.second / 2) * x.second.first;
    if (x.second.second > 0) pq.push(x);
  }
  cout << res << '\n';
  for (long long i = 1; i <= n; i++) g[i].clear(), cnt[i] = 0;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) solve();
}
