#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v, next;
  long long w;
} e[100010 * 2];
struct Node {
  long long w, size;
  bool operator<(const Node &A) const {
    return ((w - w / 2) * size) < ((A.w - A.w / 2) * A.size);
  }
};
int T, n, h[100010], vis[100010], ans;
long long S, sum, size[100010];
priority_queue<Node> q;
void addEdge(int num, int u, int v, long long w) {
  e[num].u = u;
  e[num].v = v;
  e[num].w = w;
  e[num].next = h[u];
  h[u] = num;
}
void init(int u) {
  vis[u] = 1;
  size[u] = 0;
  int flag = 0;
  for (int i = h[u]; i; i = e[i].next) {
    if (!vis[e[i].v]) {
      init(e[i].v);
      size[u] += size[e[i].v];
      flag = 1;
    }
  }
  if (!flag) size[u] = 1;
}
void dfs(int u) {
  vis[u] = 1;
  for (int i = h[u]; i; i = e[i].next) {
    if (!vis[e[i].v]) {
      Node cur;
      cur.w = e[i].w;
      cur.size = size[e[i].v];
      q.push(cur);
      sum += e[i].w * size[e[i].v];
      dfs(e[i].v);
    }
  }
}
int main() {
  scanf("%d", &T);
  while (T--) {
    while (!q.empty()) q.pop();
    scanf("%d%lld", &n, &S);
    for (int i = 1; i <= n; ++i) h[i] = 0;
    for (int i = 1, u, v, w; i < n; ++i) {
      scanf("%d%d%d", &u, &v, &w);
      addEdge(i, u, v, w);
      addEdge(i + n, v, u, w);
    }
    for (int i = 1; i <= n; ++i) vis[i] = 0;
    init(1);
    for (int i = 1; i <= n; ++i) vis[i] = 0;
    sum = ans = 0;
    dfs(1);
    while (sum > S) {
      Node cur = q.top();
      q.pop();
      sum -= (cur.w - cur.w / 2) * cur.size;
      Node next;
      next.w = cur.w / 2;
      next.size = cur.size;
      q.push(next);
      ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
