#include <bits/stdc++.h>
using namespace std;
int dfs(vector<vector<pair<int, int>>>& g, vector<bool>& vis, vector<int>& freq,
        int u) {
  if (g[u].size() == 1 && vis[g[u][0].first]) {
    return 1;
  }
  vis[u] = true;
  int c = 0;
  for (int i = 0; i < g[u].size(); i++) {
    if (!vis[g[u][i].first]) {
      int x = dfs(g, vis, freq, g[u][i].first);
      c += x;
      freq[g[u][i].second] += x;
    }
  }
  return c;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, u, v;
    long long s;
    cin >> n >> s;
    vector<vector<pair<int, int>>> g(n + 1);
    vector<int> w(n - 1);
    vector<bool> vis(n + 1, false);
    vector<int> freq(n, 0);
    for (int i = 1; i < n; i++) {
      cin >> u >> v >> w[i - 1];
      g[u].push_back({v, i - 1});
      g[v].push_back({u, i - 1});
    }
    dfs(g, vis, freq, 1);
    int moves = 0;
    long long cur = 0;
    priority_queue<pair<long long, pair<int, int>>> pq;
    for (int i = 1; i < n; i++) {
      cur += 1LL * freq[i - 1] * w[i - 1];
      pq.push(
          {1LL * freq[i - 1] * w[i - 1] - 1LL * freq[i - 1] * (w[i - 1] / 2),
           {w[i - 1] / 2, freq[i - 1]}});
    }
    while (cur > s) {
      auto temp = pq.top();
      pq.pop();
      cur -= temp.first;
      int weight = temp.second.first;
      int f = temp.second.second;
      long long reduction = 1LL * f * weight - 1LL * f * (weight / 2);
      weight /= 2;
      moves++;
      pq.push({reduction, {weight, f}});
    }
    cout << moves << endl;
  }
}
