#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-10;
const unsigned long long hashp = 131;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int maxn = 2e5 + 100;
int head[maxn], cnt, sz[maxn], du[maxn];
struct edge {
  int nxt, to, val;
} e[maxn * 2];
struct node {
  int val, num;
  bool operator<(const node& z) const {
    return 1ll * (val - val / 2) * num < 1ll * (z.val - z.val / 2) * z.num;
  }
};
void add(int a, int b, int val) {
  e[++cnt].nxt = head[a], e[cnt].to = b, e[cnt].val = val, head[a] = cnt;
}
priority_queue<node> q;
long long lft;
void dfs(int u, int fa) {
  if (du[u] == 1 && u != 1) {
    sz[u] = 1;
    return;
  }
  sz[u] = 0;
  for (int i = head[u]; i; i = e[i].nxt) {
    int to = e[i].to, val = e[i].val;
    if (to == fa) continue;
    dfs(to, u);
    sz[u] += sz[to];
    q.push(node{val, sz[to]});
    lft += 1ll * val * sz[to];
  }
}
void solve() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    long long S;
    scanf("%lld", &S);
    for (int i = 1; (i) <= (n); i++) head[i] = 0, du[i] = 0;
    cnt = 0;
    lft = 0;
    int ans = 0;
    while (!q.empty()) q.pop();
    for (int i = 1; (i) <= (n - 1); i++) {
      int x, y, z;
      scanf("%d%d%d", &x, &y, &z);
      add(x, y, z);
      add(y, x, z);
      du[x]++, du[y]++;
    }
    dfs(1, 1);
    while (lft > S) {
      node now = q.top();
      q.pop();
      lft -= 1ll * (now.val - now.val / 2) * now.num;
      ans++;
      now.val /= 2;
      q.push(now);
    }
    cout << ans << endl;
  }
}
int main() {
  solve();
  return 0;
}
