#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long, long long> > > gr[2];
priority_queue<pair<long long, pair<long long, long long> > > s[2];
long long sum = 0;
long long dfs(long long v, long long p) {
  long long l = 1;
  long long ls = 0;
  for (auto u : gr[0][v]) {
    if (u.first == p) continue;
    l = 0;
    long long k = dfs(u.first, v);
    sum += k * u.second;
    ls += k;
    s[0].push({(u.second + 1LL) / 2LL * k, {k, u.second}});
  }
  for (auto u : gr[1][v]) {
    if (u.first == p) continue;
    l = 0;
    long long k = dfs(u.first, v);
    sum += k * u.second;
    s[1].push({(u.second + 1LL) / 2LL * k, {k, u.second}});
  }
  if (l) {
    return 1;
  }
  return ls;
}
void solve() {
  long long n, S;
  cin >> n >> S;
  sum = 0;
  gr[0].clear();
  gr[0].resize(n + 1);
  gr[1].clear();
  gr[1].resize(n + 1);
  while (!s[0].empty()) s[0].pop();
  while (!s[1].empty()) s[1].pop();
  for (int i = 1; i < n; i++) {
    long long x, y, z, t;
    cin >> x >> y >> z;
    t = 0;
    gr[t][x].push_back({y, z});
    gr[t][y].push_back({x, z});
  }
  dfs(1, 1);
  long long ans = 0;
  vector<long long> ed;
  while (sum > S && s[0].size() > 0) {
    pair<long long, pair<long long, long long> > x = s[0].top();
    s[0].pop();
    sum -= x.first;
    ans++;
    ed.push_back(x.first);
    x.second.second /= 2;
    x.first = (x.second.second + 1LL) / 2LL * x.second.first;
    if (x.first <= 0) continue;
    s[0].push(x);
  }
  cout << ans << "\n";
}
int main() {
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
}
