#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, nxt;
  long long val;
} e[100010 << 1];
int t, n, fir[100010], ans, cnt;
long long S, s[100010], sum[100010], W[100010], l, r, SS;
struct P {
  int id;
  long long val;
};
priority_queue<P> q;
bool operator<(P a, P b) {
  return (a.val - a.val / 2) * s[a.id] < (b.val - b.val / 2) * s[b.id];
}
inline void add(int x, int y, long long z) {
  e[++cnt].to = y;
  e[cnt].nxt = fir[x];
  e[cnt].val = z;
  fir[x] = cnt;
}
long long dfs(int x, int fa) {
  long long ss = 0;
  bool bb = false;
  for (int i = fir[x], y; i; i = e[i].nxt) {
    y = e[i].to;
    if (y == fa) continue;
    bb = 1;
    ss += dfs(y, x);
    W[y] = e[i].val;
    sum[y] = s[y] * e[i].val;
  }
  if (!bb) {
    s[x] = 1;
    return s[x];
  } else {
    s[x] = ss;
    return ss;
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d %lld", &n, &S);
    cnt = ans = 0, SS = 0;
    for (int i = 1, u, v; i < n; i++) {
      long long w;
      scanf("%d %d %lld", &u, &v, &w);
      add(u, v, w), add(v, u, w);
    }
    dfs(1, 0);
    for (int i = 2; i <= n; i++) q.push((P){i, W[i]}), SS += sum[i];
    int xx;
    long long yy;
    while (SS > S) {
      xx = q.top().id, yy = q.top().val;
      q.pop(), ++ans;
      SS -= yy * s[xx] - (yy / 2) * s[xx];
      q.push((P){xx, yy / 2});
    }
    for (int i = 1; i <= n; i++) fir[i] = s[i] = sum[i] = W[i] = 0;
    while (!q.empty()) q.pop();
    printf("%d\n", ans);
  }
  return 0;
}
