#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int powm(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b & 1) res = (res * 1LL * a) % mod;
    b >>= 1LL;
    a = (a * 1LL * a) % mod;
  }
  return res;
}
const int N = 1e5 + 5;
vector<pair<int, long long int>> g[N];
long long int nodes[N], edge[N], cost[N];
long long int total = 0;
void dfs(int v, int par) {
  bool b = 0;
  for (auto u : g[v]) {
    int uu = u.first;
    long long int w = u.second;
    if (uu == par) continue;
    b = 1;
    edge[uu] = w;
    dfs(uu, v);
    nodes[v] += nodes[uu];
  }
  if (!b) {
    nodes[v] = 1;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    long long int s;
    cin >> s;
    total = 0;
    for (int i = 0; i <= n; i++) {
      g[i].clear();
      nodes[i] = 0;
      cost[i] = 0;
      edge[i] = 0;
    }
    for (int i = 0; i < n - 1; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      --a, --b;
      g[a].push_back({b, c});
      g[b].push_back({a, c});
    }
    dfs(0, -1);
    priority_queue<pair<long long int, long long int>> pq;
    for (int i = 1; i < n; i++) {
      long long int diff = (edge[i] - (edge[i] / 2));
      diff *= nodes[i];
      total += edge[i] * nodes[i];
      pq.push({diff, i});
    }
    long long int ans = 0;
    while (total > s) {
      long long int diff = pq.top().first;
      long long int v = pq.top().second;
      pq.pop();
      total -= (diff);
      edge[v] /= 2;
      diff = ((edge[v] - (edge[v] / 2))) * nodes[v];
      pq.push({diff, v});
      ans++;
    }
    cout << ans << '\n';
  }
  return 0;
}
