#include <bits/stdc++.h>
using namespace std;
template <class X>
bool mini(X& a, const X& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class X>
bool maxi(X& a, const X& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef const int& ci;
const int N = 1e5 + 1;
int n;
long long s;
vector<pair<int, int>> ke[N];
long long dp[N];
priority_queue<pair<long long, pair<int, int>>> q;
long long curs = 0;
void enter() {}
void dfs(int u, int pa = 0) {
  for (auto& [v, w] : ke[u])
    if (v != pa) {
      dfs(v, u);
      q.emplace(dp[v] * w - dp[v] * (w / 2), pair<int, int>(w, v));
      curs += dp[v] * w;
      dp[u] += dp[v];
    }
  if (ke[u].size() == 1 && u != 1) dp[u] = 1;
}
void solve() {
  int test;
  for (cin >> test; test--;) {
    cin >> n >> s;
    for (int i = 1, _b = (n) + 1; i < _b; ++i) ke[i].clear(), dp[i] = 0;
    for (int i = 1, u, v, w; i < n; ++i) {
      cin >> u >> v >> w;
      ke[u].emplace_back(v, w);
      ke[v].emplace_back(u, w);
    }
    curs = 0;
    dfs(1);
    int res = 0;
    while (curs > s) {
      long long del = q.top().first, w = q.top().second.first,
                v = q.top().second.second;
      q.pop();
      curs -= del, ++res;
      w >>= 1;
      if (!w) continue;
      q.emplace(dp[v] * w - dp[v] * (w / 2), pair<int, int>(w, v));
    }
    while (q.size()) q.pop();
    cout << res << '\n';
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  enter();
  solve();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms";
}
