#include <bits/stdc++.h>
using namespace std;
const long long INF = 2147483647;
const long long LONGINF = 9223372036854775807;
const long long MOD = 998244353;
auto cmp = [](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;
};
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
               decltype(cmp)>
    q(cmp);
vector<vector<pair<long long, long long>>> adj;
long long S = 0;
long long dfs(long long v, long long p) {
  if (adj[v].size() == 1 && adj[v].front().first == p) return 1;
  long long sum = 0;
  for (auto& i : adj[v]) {
    if (i.first != p) {
      long long c = dfs(i.first, v);
      sum += c;
      S += i.second * c;
      q.push({i.second, c});
    }
  }
  return sum;
}
void solve() {
  long long n, s;
  cin >> n >> s;
  adj.resize(n + 1);
  for (long long i = 0; i < n - 1; ++i) {
    long long v, u, w;
    cin >> v >> u >> w;
    adj[v].push_back({u, w});
    adj[u].push_back({v, w});
  }
  dfs(1, -1);
  long long moves = 0;
  while (S > s) {
    pair<long long, long long> big = q.top();
    q.pop();
    long long delta = (big.first - big.first / 2) * big.second;
    S -= delta;
    big.first /= 2;
    q.push(big);
    ++moves;
  }
  cout << moves << '\n';
  while (!q.empty()) q.pop();
  adj = vector<vector<pair<long long, long long>>>();
  S = 0;
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  std::ios_base::sync_with_stdio(0);
  bool mult = true;
  if (mult) {
    long long t;
    cin >> t;
    while (t--) solve();
  } else
    solve();
}
