#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> adj[int(1e6)];
vector<long long> cnt(int(1e6), 0);
priority_queue<pair<long long, pair<long long, long long>>> pq;
long long n, t, suma;
void dfs(int curr, int par = -1) {
  if (adj[curr].size() == 1 and curr != 1) {
    cnt[curr] = 1;
    return;
  }
  for (auto it : adj[curr]) {
    if (it.first != par) {
      dfs(it.first, curr);
      long long x = cnt[it.first];
      long long y = it.second;
      suma -= x * y;
      pq.push({x * y - (x * (long long)(y / 2)), {x, y}});
      cnt[curr] += x;
    }
  }
}
void reset() {
  for (int i = 1; i <= n; i++) {
    adj[i].clear();
    cnt[i] = 0;
  }
  while (!pq.empty()) pq.pop();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t;
  int u, v, w;
  while (t--) {
    cin >> n >> suma;
    for (int i = 0; i < n - 1; i++) {
      cin >> u >> v >> w;
      adj[u].push_back({v, w});
      adj[v].push_back({u, w});
    }
    dfs(1);
    pair<long long, pair<long long, long long>> it1;
    long long ans = 0;
    while (suma < 0) {
      long long x, y;
      it1 = pq.top();
      pq.pop();
      suma += (it1.first);
      x = it1.second.first;
      y = it1.second.second;
      y = y / 2;
      pq.push({x * y - (x * (long long)(y / 2)), {x, y}});
      ans += 1;
    }
    reset();
    cout << ans << endl;
  }
  return 0;
}
