#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 100002;
int t;
int n;
long long S;
struct Edge {
  int u;
  int v;
  long long w;
};
Edge edges[N_MAX];
vector<int> g[N_MAX];
int sub[N_MAX];
void dfs(int u, int parent = -1) {
  sub[u] = 0;
  for (int v : g[u])
    if (v != parent) {
      dfs(v, u);
      sub[u] += sub[v];
    }
  if ((int)g[u].size() - (parent != -1) == 0) sub[u] = 1;
}
priority_queue<pair<long long, int> > pq;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> S;
    for (int i = 1; i < n; i++) cin >> edges[i].u >> edges[i].v >> edges[i].w;
    for (int i = 1; i < n; i++) {
      g[edges[i].u].push_back(edges[i].v);
      g[edges[i].v].push_back(edges[i].u);
    }
    dfs(1);
    for (int i = 1; i < n; i++)
      if (sub[edges[i].u] > sub[edges[i].v]) swap(edges[i].u, edges[i].v);
    long long s = 0;
    for (int i = 1; i < n; i++) {
      s += edges[i].w * sub[edges[i].u];
      pq.push(make_pair((edges[i].w + 1) / 2 * sub[edges[i].u], i));
    }
    int ans = 0;
    while (s > S) {
      int t = pq.top().second;
      pq.pop();
      s -= ((edges[t].w + 1) / 2) * sub[edges[t].u];
      edges[t].w /= 2;
      pq.push(make_pair((edges[t].w + 1) / 2 * sub[edges[t].u], t));
      ans++;
    }
    while (!pq.empty()) pq.pop();
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) g[i].clear();
  }
  return 0;
}
