#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 9;
const double ep = 1e-7;
const int mod = 1e9 + 7;
const double pi = acos(-1);
const int INF = INT_MAX;
long long n, s, ans;
int head[maxn], cnt;
long long son[maxn];
struct node {
  int to, val, nex;
} a[maxn];
void add(int u, int v, long long val) {
  a[++cnt].to = v;
  a[cnt].val = val;
  a[cnt].nex = head[u];
  head[u] = cnt;
}
long long sum, cntt;
struct cmp {
  bool operator()(pair<long long, long long> a, pair<long long, long long> b) {
    return a.first * a.second - a.first / 2 * a.second <
           b.first * b.second - b.first / 2 * b.second;
  }
};
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               cmp>
    pq;
void dfs(int x, int p) {
  bool ju = 0;
  son[x] = 0;
  for (int i = head[x]; i; i = a[i].nex) {
    int v = a[i].to, val = a[i].val;
    if (v == p) continue;
    dfs(v, x);
    ju = 1;
    son[x] += son[v];
    long long tot = son[v];
    while (val * tot > s) ans++, val /= 2;
    if (val) pq.push(make_pair(val, tot));
    sum += val * tot;
  }
  if (!ju) son[x] = 1;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    cnt = 0;
    sum = ans = cntt = 0;
    while (!pq.empty()) pq.pop();
    scanf("%lld%lld", &n, &s);
    for (int i = 1; i <= n; i++) son[i] = head[i] = 0;
    for (int i = 1; i < n; i++) {
      int u, v;
      long long w;
      scanf("%d%d%lld", &u, &v, &w);
      add(u, v, w);
      add(v, u, w);
    }
    dfs(1, -1);
    if (sum <= s) {
      printf("%lld\n", ans);
      continue;
    }
    while (!pq.empty()) {
      pair<long long, long long> pp = pq.top();
      pq.pop();
      sum = sum - pp.first * pp.second;
      pp.first /= 2;
      sum = sum + pp.first * pp.second;
      if (pp.first) pq.push(pp);
      ans++;
      if (sum <= s) break;
    }
    printf("%lld\n", ans);
  }
}
