#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int>> adj[200100];
long long int cnt_leaf[200100];
long long int value_node[200100];
int vis[200100];
void dfs(long long int src) {
  vis[src] = 1;
  if (adj[src].size() == 1) cnt_leaf[src] = 1;
  for (auto xt : adj[src]) {
    if (!vis[xt.first]) {
      dfs(xt.first);
      cnt_leaf[src] += cnt_leaf[xt.first];
    } else
      value_node[src] = xt.second;
  }
}
int main() {
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int n, S, total = 0;
    cin >> n >> S;
    for (int i = 1; i <= n - 1; i++) {
      long long int x, y, cost;
      cin >> x >> y >> cost;
      adj[x].push_back({y, cost});
      adj[y].push_back({x, cost});
    }
    dfs(1);
    priority_queue<pair<long long int, long long int>> pq;
    for (long long int i = 2; i <= n; i++) {
      total += cnt_leaf[i] * value_node[i];
      long long int diff =
          (cnt_leaf[i] * value_node[i]) - (cnt_leaf[i] * (value_node[i] / 2));
      pq.push({diff, i});
    }
    long long int ans = 0;
    while (total > S) {
      ans += 1;
      pair<long long int, long long int> pr = pq.top();
      pq.pop();
      long long int i = pr.second;
      total -= (cnt_leaf[i] * value_node[i]);
      value_node[i] /= 2;
      total += (cnt_leaf[i] * value_node[i]);
      long long int new_diff =
          (cnt_leaf[i] * value_node[i]) - (cnt_leaf[i] * (value_node[i] / 2));
      pq.push({new_diff, i});
    }
    cout << ans << endl;
    for (int i = 0; i <= n + 1; i++) {
      value_node[i] = 0;
      cnt_leaf[i] = 0;
      vis[i] = false;
      adj[i].clear();
    }
  }
  return 0;
}
