#include <bits/stdc++.h>
using namespace std;
long long t, n, S, u, v, w, f[100001], sum, used[100001];
struct TP {
  long long dif;
  long long a;
  long long cnt;
};
vector<pair<long long, long long> > g[100001];
struct cmp {
  bool operator()(TP a, TP b) { return a.dif < b.dif; }
};
priority_queue<TP, vector<TP>, cmp> h;
void DFS(int u) {
  used[u] = 1;
  if (g[u].size() == 1 && u != 1) {
    f[u] = 1;
    return;
  }
  for (int i = 0; i < g[u].size(); i++) {
    long long v = g[u][i].first;
    long long dv = g[u][i].second;
    if (used[v] == 0) {
      DFS(v);
      f[u] += f[v];
      sum += f[v] * dv;
      h.push({f[v] * dv - f[v] * (dv / 2), dv, f[v]});
    }
  }
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> S;
    sum = 0;
    for (int i = 1; i < n; i++) {
      cin >> u >> v >> w;
      g[u].push_back({v, w});
      g[v].push_back({u, w});
    }
    DFS(1);
    long long ans = 0;
    while (sum > S) {
      TP x = h.top();
      long long dif = x.dif;
      long long a = x.a;
      long long cnt = x.cnt;
      h.pop();
      long long New = a / 2 * cnt;
      h.push({New - (((a / 2) / 2) * cnt), a / 2, cnt});
      sum -= dif;
      ans++;
    }
    cout << ans << "\n";
    while (h.size()) {
      h.pop();
    }
    for (int i = 1; i <= n; i++) {
      f[i] = 0;
      used[i] = 0;
      g[i].clear();
    }
  }
}
