#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long MX = 1e5 + 100;
const long long INF = 1e9;
vector<pair<int, int> > g[MX], e;
priority_queue<pair<long long, long long> > q;
int vis[MX];
long long sum;
long long dfs(int u) {
  vis[u] = 1;
  long long c = 0, c1, w;
  for (pair<long long, long long> p : g[u]) {
    int v = p.first;
    w = p.second;
    if (!vis[v]) {
      c1 = dfs(v);
      e.push_back({w, c1});
      sum += (w * c1);
      q.push({(w - (w / 2)) * c1, e.size() - 1});
      c += c1;
    }
  }
  if (c == 0)
    return 1;
  else
    return c;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t, n, u, v, w;
  long long s;
  cin >> t;
  while (t--) {
    cin >> n >> s;
    for (int i = 1; i < n; ++i) {
      cin >> u >> v >> w;
      g[u].push_back({v, w});
      g[v].push_back({u, w});
    }
    memset(vis, 0, sizeof(vis));
    sum = 0;
    dfs(1);
    long long ans = 0, s1, it, w, c1;
    while (sum > s) {
      ++ans;
      s1 = q.top().first;
      it = q.top().second;
      q.pop();
      sum -= s1;
      e[it].first /= 2;
      w = e[it].first;
      c1 = e[it].second;
      q.push({(w - (w / 2)) * c1, it});
    }
    cout << ans << '\n';
    for (int i = 1; i < n + 1; ++i) g[i].clear();
    while (!q.empty()) q.pop();
  }
  return 0;
}
