#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> adj[100002];
pair<long long, long long> lvl[100002];
long long w, ed;
long long dfs(long long u, long long p) {
  long long to = 0;
  bool fg = false;
  for (auto x : adj[u]) {
    if (x.first != p) {
      long long a = dfs(x.first, u);
      lvl[++ed] = {x.second, a};
      to += a, w += (x.second * a);
      fg = true;
    }
  }
  if (adj[u].size() == 1 && !fg) to++;
  return to;
}
int main() {
  long long t, n, s, i, u, v, j, cnt;
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld %lld", &n, &s);
    priority_queue<pair<long long, pair<long long, long long>>> pq;
    for (i = 1; i < n; i++) {
      scanf("%lld %lld %lld", &u, &v, &w);
      adj[u].push_back({v, w});
      adj[v].push_back({u, w});
    }
    ed = u = w = cnt = 0;
    dfs(1, 0);
    for (i = 1; i <= ed; i++) {
      u = lvl[i].first, v = lvl[i].second;
      j = w - (w - (v * u) + ((u / 2) * v));
      pq.push({j, {v, u}});
    }
    while (w > s) {
      pair<long long, pair<long long, long long>> a = pq.top();
      pq.pop();
      v = a.second.first, u = a.second.second;
      w = w - (u * v) + ((u / 2) * v);
      u /= 2;
      j = w - (w - (v * u) + ((u / 2) * v));
      pq.push({j, {v, u}});
      cnt++;
    }
    printf("%lld\n", cnt);
    for (i = 0; i <= n; i++) adj[i].clear();
  }
  return 0;
}
