#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to;
  long long w;
};
void dfs(vector<vector<edge>>& G, int v, int p, vector<int>& cnt) {
  if (G[v].size() == 1 && v != 0) {
    cnt[v] = 1;
    return;
  }
  for (auto& [u, w] : G[v]) {
    if (p == u) continue;
    dfs(G, u, v, cnt);
    cnt[v] += cnt[u];
  }
}
void dfs2(vector<vector<edge>>& G, int v, int p,
          set<tuple<long long, long long, long long>>& M, long long& sum,
          const vector<int>& cnt) {
  for (auto& [u, w] : G[v]) {
    if (u == p) continue;
    dfs2(G, u, v, M, sum, cnt);
    M.insert(make_tuple(-cnt[u] * (w - w / 2), w, u));
    sum += (cnt[u] * w);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    long long S;
    cin >> n >> S;
    vector<vector<edge>> G(n);
    for (int i = 0; i < n - 1; ++i) {
      int a, b;
      long long w;
      cin >> a >> b >> w;
      --a;
      --b;
      G[a].push_back({b, w});
      G[b].push_back({a, w});
    }
    vector<int> cnt(n);
    dfs(G, 0, 0, cnt);
    set<tuple<long long, long long, long long>> M;
    int ans = 0;
    long long sum = 0;
    dfs2(G, 0, 0, M, sum, cnt);
    while (sum > S) {
      sum += get<0>(*M.begin());
      long long w = get<1>(*M.begin());
      int j = get<2>(*M.begin());
      w = w / 2;
      M.erase(M.begin());
      M.insert(make_tuple(-cnt[j] * (w - w / 2), w, j));
      ++ans;
    }
    cout << ans << "\n";
  }
  return 0;
}
