#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   long long s, total, ans, leaves[maxn];   int n;   vector<pair<long long, long long>> tree[maxn];   void dfs(int u, int prev,            priority_queue<pair<long long, pair<long long, long long>>>& pq) {     leaves[u] = (long long)(tree[u].size() == 1);     for (auto e : tree[u]) {       long long v = e.second, w = e.first;       if (v == prev) continue;       dfs(v, u, pq);       leaves[u] += leaves[v];       pq.push({w * leaves[v] - w / 2ll * leaves[v], {w, leaves[v]}});       total += w * leaves[v];     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int T;     cin >> T;     while (T--) {       cin >> n >> s;       for (int i = 0; i < n; ++i) {         leaves[i] = 0;         tree[i].clear();       }       for (int i = 0; i < n - 1; ++i) {         long long u, v, w;         cin >> u >> v >> w;         u--, v--;         tree[u].push_back({w, v});         tree[v].push_back({w, u});       }       priority_queue<pair<long long, pair<long long, long long>>> pq;       total = ans = 0;       dfs(0, -1, pq);       while (total > s) {         auto cur = pq.top();         pq.pop();         long long w = cur.second.first, cnt = cur.second.second;         total -= w * cnt;         w /= 2ll;         total += w * cnt;         if (w > 0ll) pq.push({w * cnt - w / 2ll * cnt, {w, cnt}});         ans++;       }       cout << ans << endl;     }     return 0;   }   