#include <bits/stdc++.h>   using namespace std;   template <class T>   T modulo(T x, T p) {     if (x >= 0) return x % p;     return p + x % p;   }   template <class T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return a * b / gcd(a, b);   }   int dfs_paths(       int u, int prev, vector<vector<pair<long long, long long> > > &G,       long long &cur,       priority_queue<pair<long long, pair<long long, long long> > > &pqw) {     long long paths, total = 0, profit;     for (pair<long long, long long> e : G[u]) {       if (e.second == prev) continue;       paths = dfs_paths(e.second, u, G, cur, pqw);       profit = e.first * paths - (e.first / 2) * paths;       pqw.push({profit, {e.first, paths}});       cur += e.first * paths;       total += paths;     }     return max(1ll, total);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long n, S;       cin >> n >> S;       vector<vector<pair<long long, long long> > > G(n);       int u, v;       long long w;       for (int i = 0; i < n - 1; i++) {         cin >> u >> v >> w;         u--;         v--;         G[u].push_back({w, v});         G[v].push_back({w, u});       }       long long cur = 0;       priority_queue<pair<long long, pair<long long, long long> > > pqw;       dfs_paths(0, -1, G, cur, pqw);       long long moves = 0, mult;       pair<long long, pair<long long, long long> > e;       while (cur > S) {         e = pqw.top();         pqw.pop();         w = e.second.first / 2;         mult = e.second.second;         cur -= e.first;         pqw.push({w * mult - (w / 2) * mult, {w, mult}});         moves++;       }       cout << moves <<   n ;     }     return 0;   }   