#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-7;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, -1, 1, 0};
long long power(long long x, long long y) {
  long long ans = 1;
  x = x;
  while (y > 0) {
    if (y & 1) ans = (ans * x);
    y = y >> 1;
    x = (x * x);
  }
  return ans;
}
long long sqr(long long x) { return x * x; }
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <class T>
inline void chmax(T &x, T y) {
  x = max((x), (y));
}
template <class T>
inline void chmin(T &x, T y) {
  x = min((x), (y));
}
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <typename T>
T powm(T a, T b, long long m) {
  T cnt = 1;
  while (b > 0) {
    if (b % 2 == 1) cnt = (cnt * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return cnt % m;
}
long long ncr(long long n, long long r) {
  long long ans = 1;
  if (r > n) return 0;
  if (r > n - r) r = n - r;
  for (long long i = 0; i < r; i++) {
    ans *= (n - i);
    ans /= (i + 1);
  }
  return ans;
}
const int MOD = 1000000007;
const int N = 400010;
struct compare {
  bool operator()(const int &a, const int &b) const { return a > b; }
};
void prec() {}
long long n, S, u, v, w[N], cnt[N], tot;
vector<pair<long long, long long> > g[N];
void dfs(long long v, long long p = -1) {
  if ((long long)g[v].size() == 1) cnt[p] = 1;
  for (auto &[to, id] : g[v]) {
    if (id == p) continue;
    dfs(to, id);
    if (p != -1) cnt[p] += cnt[id];
  }
}
long long diff(long long i) { return w[i] * cnt[i] - (w[i] / 2) * cnt[i]; }
void run() {
  cin >> n >> S;
  tot = 0;
  for (int i = 0; i <= n; ++i) cnt[i] = 0;
  for (int i = 0; i <= n; ++i) g[i].clear();
  for (int i = 0; i < n - 1; ++i) {
    cin >> u >> v >> w[i];
    u--, v--;
    g[u].push_back(make_pair(v, i));
    g[v].push_back(make_pair(u, i));
  }
  dfs(0);
  set<pair<long long, long long> > st;
  for (int i = 0; i < n - 1; ++i) {
    st.insert(make_pair(diff(i), i));
    tot += w[i] * cnt[i];
  }
  long long ans = 0;
  while (tot > S) {
    long long id = st.rbegin()->second;
    st.erase(prev(st.end()));
    tot -= diff(id);
    w[id] /= 2;
    st.insert(make_pair(diff(id), id));
    ++ans;
  }
  cout << ans << "\n";
}
int32_t main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int tc = 1;
  cin >> tc;
  prec();
  for (long long i = 0; i < tc; ++i) run();
  return 0;
}
