#include <bits/stdc++.h>
using namespace std;
long long t, n, s, tot, cnt[100001], w[100001];
struct edge {
  long long v, w, id, sum;
};
vector<edge> g[100001];
struct node {
  int id;
  long long w;
  friend bool operator<(const node &a, const node &b) {
    return (a.w - a.w / 2) * cnt[a.id] < (b.w - b.w / 2) * cnt[b.id];
  }
};
priority_queue<node> q;
void dfs(int u, int fa) {
  bool flag = 0;
  for (int i = 0; i < g[u].size(); i++) {
    edge tmp = g[u][i];
    if (tmp.v == fa) continue;
    flag = 1;
    w[tmp.v] = tmp.w;
    dfs(tmp.v, u);
    cnt[u] += cnt[tmp.v];
  }
  if (!flag) {
    cnt[u] = 1;
    return;
  }
  for (int i = 0; i < g[u].size(); i++) {
    if (g[u][i].v == fa) continue;
    g[u][i].id = cnt[g[u][i].v];
  }
}
void reset() {
  while (!q.empty()) q.pop();
  memset(cnt, 0, sizeof(cnt));
  memset(w, 0, sizeof(w));
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> s;
    int ans;
    ans = tot = 0;
    reset();
    for (int i = 0; i < 100001; i++) g[i].clear();
    for (int i = 1; i < n; i++) {
      int u, v, w;
      cin >> u >> v >> w;
      g[u].push_back((edge){v, w, ++tot, 0});
      g[v].push_back((edge){u, w, ++tot, 0});
    }
    dfs(1, -1);
    long long sum = 0;
    for (int i = 2; i <= n; i++)
      q.push((node){i, w[i]}), sum += (long long)w[i] * (long long)cnt[i];
    while (sum > s) {
      ans++;
      int id = q.top().id;
      long long _ = q.top().w;
      q.pop();
      sum -= (_ - _ / 2) * cnt[id];
      q.push((node){id, _ / 2});
    }
    cout << ans << endl;
  }
}
