#include <bits/stdc++.h>
using namespace std;
long long int DFS(
    long long int i, long long int parent,
    vector<pair<long long int, long long int> > Tree[],
    priority_queue<pair<long long int, pair<long long int, long long int> > >
        &Sum,
    long long int &TotalSum) {
  long long int TotalLeaves = 0, leaves = 0;
  for (long long int j = 0; j < Tree[i].size(); j++) {
    if (Tree[i][j].first == parent) continue;
    leaves = DFS(Tree[i][j].first, i, Tree, Sum, TotalSum);
    Sum.push(
        make_pair(leaves * Tree[i][j].second - leaves * (Tree[i][j].second / 2),
                  make_pair(Tree[i][j].second, leaves)));
    TotalSum += (leaves * Tree[i][j].second);
    TotalLeaves += leaves;
  }
  if (TotalLeaves == 0) TotalLeaves = 1;
  return TotalLeaves;
}
void solve() {
  long long int n, u, v, w;
  long long int S;
  scanf("%lld %lld", &n, &S);
  vector<pair<long long int, long long int> > Tree[n + 1];
  for (long long int i = 0; i < n - 1; i++) {
    scanf("%lld %lld %lld", &u, &v, &w);
    Tree[u].push_back(make_pair(v, w));
    Tree[v].push_back(make_pair(u, w));
  }
  priority_queue<pair<long long int, pair<long long int, long long int> > > Sum;
  long long int TotalSum = 0;
  DFS(1, -1, Tree, Sum, TotalSum);
  pair<long long int, pair<long long int, long long int> > TopValue;
  long long int operations = 0;
  while (TotalSum > S) {
    TopValue = Sum.top();
    Sum.pop();
    TotalSum -= TopValue.first;
    TopValue.second.first = TopValue.second.first / 2;
    TopValue.first = (TopValue.second.first * TopValue.second.second -
                      (TopValue.second.first / 2) * TopValue.second.second);
    Sum.push(TopValue);
    operations++;
  }
  cout << operations << endl;
}
int main() {
  long long int t;
  scanf("%lld", &t);
  while (t--) {
    solve();
  }
  return 0;
}
