#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
struct Node {
  long long s, t;
  long long v;
  long long w;
  long long cnt;
  bool friend operator<(Node aa, Node bb) { return aa.w < bb.w; }
} a[MAXN];
long long n;
long long s;
long long vis[MAXN];
vector<long long> G[MAXN];
void dfs(long long u, long long fa) {
  long long f = 0;
  for (long long i = 0; i < G[u].size(); i++) {
    long long v = G[u][i];
    if (v != fa) {
      f = 1;
      dfs(v, u);
      vis[u] += vis[v];
    }
  }
  if (f == 0) vis[u] = 1;
}
void init() {
  for (long long i = 1; i <= n; i++) {
    G[i].clear();
    vis[i] = 0;
  }
}
void solve() {
  long long sum = 0;
  dfs(1, -1);
  priority_queue<Node> Q;
  for (long long i = 1; i < n; i++) {
    a[i].cnt = min(vis[a[i].s], vis[a[i].t]);
    a[i].w = a[i].cnt * (a[i].v - a[i].v / 2);
    sum += a[i].cnt * a[i].v;
    Q.push(a[i]);
  }
  long long cnt = 0;
  while (1) {
    if (sum <= s) {
      break;
    }
    Node u = Q.top();
    Q.pop();
    sum -= u.w;
    u.v = u.v / 2;
    u.w = u.cnt * (u.v - u.v / 2);
    Q.push(u);
    cnt++;
  }
  cout << cnt << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long T;
  cin >> T;
  while (T--) {
    cin >> n >> s;
    init();
    for (long long i = 1; i < n; i++) {
      cin >> a[i].s >> a[i].t >> a[i].v;
      G[a[i].s].push_back(a[i].t);
      G[a[i].t].push_back(a[i].s);
    }
    solve();
  }
}
