#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 10;
int tol = 0;
int head[MAXN];
int net[MAXN];
int to[MAXN];
long long val[MAXN];
long long vval[MAXN];
int siz[MAXN];
struct node {
  int id;
  long long val;
  bool operator<(const node& b) const {
    return (vval[id] - vval[id] / 2) * siz[id] <
           (vval[b.id] - vval[b.id] / 2) * siz[b.id];
  }
};
priority_queue<node> q;
void add(int u, int v, long long va) {
  tol++;
  net[tol] = head[u];
  to[tol] = v;
  head[u] = tol;
  val[tol] = va;
}
void init(int n) {
  tol = 0;
  for (int i = 0; i <= n * 2 + 10; i++) {
    head[i] = net[i] = to[i] = val[i] = vval[i] = siz[i] = 0;
  }
  while (!q.empty()) {
    q.pop();
  }
}
int dfs(int u, int fa) {
  siz[u] = 0;
  int leaf = 1;
  for (int i = head[u]; i != 0; i = net[i]) {
    int v = to[i];
    if (v == fa) continue;
    leaf = 0;
    vval[v] = val[i];
    siz[u] += dfs(v, u);
  }
  siz[u] += leaf;
  return siz[u];
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    long long s;
    scanf("%d%lld", &n, &s);
    val[1] = 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, 0);
    long long ss = 0;
    for (int i = 2; i <= n; i++) {
      q.push(node{i, vval[i] * siz[i]});
      ss += vval[i] * siz[i];
    }
    long long ans = 0;
    while (ss > s) {
      node tmp = q.top();
      ss -= tmp.val;
      vval[tmp.id] = vval[tmp.id] / 2;
      ss += vval[tmp.id] * siz[tmp.id];
      q.pop();
      q.push(node{tmp.id, vval[tmp.id] * siz[tmp.id]});
      ans++;
    }
    printf("%lld\n", ans);
    init(tol);
  }
  return 0;
}
