#include <bits/stdc++.h>
using namespace std;
int N;
long long S;
vector<pair<long long, long long> > adj[101010];
int sz[101010];
long long w[101010];
priority_queue<pair<long long, long long> > pq;
bool lf(int v) { return adj[v].size() == 1 && v != 1; }
void dfs(int v, int p) {
  if (lf(v))
    sz[v] = 1;
  else
    sz[v] = 0;
  for (pair<long long, long long> i : adj[v]) {
    if (i.first == p) continue;
    w[i.first] = i.second;
    dfs(i.first, v);
    sz[v] += sz[i.first];
  }
}
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    scanf("%d%lld", &N, &S);
    for (int i = 1; i <= N; i++) adj[i].clear();
    for (int i = 1; i < N; i++) {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      adj[a].emplace_back(b, c);
      adj[b].emplace_back(a, c);
    }
    dfs(1, 0);
    while (pq.size()) pq.pop();
    long long sum = 0;
    for (int i = 2; i <= N; i++) {
      sum += (long long)w[i] * sz[i];
      pq.emplace((w[i] + 1) / 2 * sz[i], i);
    }
    int ans = 0;
    while (sum > S) {
      pair<long long, long long> t = pq.top();
      pq.pop();
      sum -= t.first;
      w[t.second] /= 2;
      pq.emplace((w[t.second] + 1) / 2 * sz[t.second], t.second);
      ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
