#include <bits/stdc++.h>
using namespace std;
long long int max(long long int a, long long int b) {
  if (a > b) {
    return a;
  }
  return b;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
long long int min(long long int a, long long int b) {
  if (a < b) {
    return a;
  }
  return b;
}
long long int power(long long int x, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n % 2 == 1) {
      res = (res * x);
    }
    x = (x * x);
    n = n / 2;
  }
  return res;
}
long long int factorialNumInverse[1000001];
long long int naturalNumInverse[1000001];
long long int fact[1000001];
void InverseofNumber(long long int n, long long int p) {
  naturalNumInverse[0] = naturalNumInverse[1] = 1;
  for (long long int i = 2; i <= n; i++)
    naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
}
void InverseofFactorial(long long int n, long long int p) {
  factorialNumInverse[0] = factorialNumInverse[1] = 1;
  for (long long int i = 2; i <= n; i++)
    factorialNumInverse[i] =
        (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
}
void factorial(long long int n, long long int p) {
  fact[0] = 1;
  for (long long int i = 1; i <= n; i++) {
    fact[i] = (fact[i - 1] * i) % p;
  }
}
long long int nCrModp(long long int n, long long int r, long long int p) {
  long long int ans =
      ((fact[n] * factorialNumInverse[r]) % p * factorialNumInverse[n - r]) % p;
  return ans;
}
struct cmp {
  bool operator()(pair<long long int, long long int> p1,
                  pair<long long int, long long int> p2) {
    return ((p1.first - p1.first / 2) * p1.second) >
           ((p2.first - p2.first / 2) * p2.second);
  }
};
long long int sub[3000005];
vector<pair<long long int, long long int> > adj[3000005];
long long int sum;
multiset<pair<long long int, long long int>, cmp> m;
void dfs(int root, int par) {
  long long int c = 0;
  for (int i = 0; i < adj[root].size(); i++) {
    long long int val = adj[root][i].first;
    long long int cst = adj[root][i].second;
    if (val != par) {
      dfs(val, root);
      c += sub[val];
      sum += sub[val] * cst;
      m.insert({cst, sub[val]});
    }
  }
  if (c == 0) {
    c = 1;
  }
  sub[root] = c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int tc;
  cin >> tc;
  factorial(200005, 1000000007);
  InverseofNumber(200005, 1000000007);
  InverseofFactorial(200005, 1000000007);
  while (tc--) {
    long long int n, s;
    cin >> n >> s;
    m.clear();
    for (int i = 1; i <= n + 1; i++) {
      adj[i].clear();
    }
    sum = 0;
    for (int i = 0; i < n - 1; i++) {
      long long int v, u, w;
      cin >> u >> v >> w;
      adj[u].push_back({v, w});
      adj[v].push_back({u, w});
    }
    dfs(1, 0);
    long long int ans = 0;
    while (sum > s) {
      ans++;
      pair<long long int, long long int> it = *m.begin();
      m.erase(m.begin());
      sum -= it.first * it.second;
      it.first /= 2;
      if (it.first) {
        sum += it.first * it.second;
        m.insert(it);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
