#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long INF = 1000000000000000000LL;
const int N = 1e5 + 5;
long long SUM, sum = 0;
long long l[N];
vector<pair<long long, long long>> v[N];
priority_queue<pair<long long, pair<long long, long long>>> q;
void dfs(long long n, long long s, long long p) {
  long long c = 0;
  for (auto x : v[n]) {
    long long y = x.first, w = x.second;
    if (y != p) {
      dfs(y, s + 1LL * w, n);
      c++;
      l[n] += l[y];
      q.push({w * l[y] - w / 2 * l[y], {w, l[y]}});
    }
  }
  if (!c) sum += s;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n >> SUM;
    q = priority_queue<pair<long long, pair<long long, long long>>>();
    memset(l, 0, sizeof(l));
    sum = 0;
    for (long long x = 0; x < N; x++) v[x].clear();
    for (long long x = 1; x < n; x++) {
      long long a, b, w;
      cin >> a >> b >> w;
      v[a].push_back({b, w});
      v[b].push_back({a, w});
    }
    for (long long x = 2; x <= n; x++)
      if (v[x].size() == 1) l[x] = 1;
    dfs(1, 0, 0);
    long long ans = 0;
    while (sum > SUM) {
      long long con = q.top().second.first * q.top().second.second,
                w = q.top().second.first, tim = q.top().second.second;
      q.pop();
      sum -= con;
      w /= 2;
      sum += w * tim;
      ans++;
      q.push({w * tim - w / 2 * tim, {w, tim}});
    }
    cout << ans << "\n";
  }
  return 0;
}
