#include <bits/stdc++.h>
using namespace std;
template <typename T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const long double PI = 3.14159265358979323846;
const long double E = 2.718281828459;
const long long SIZE = 3e2 + 3;
const long long MOD = 1e9 + 7;
long long myMod(long long n) { return (n % MOD + MOD) % MOD; }
long long n, s;
long long current;
vector<vector<pair<long long, long long>>> edges;
vector<long long> weights, sizes;
long long dfs(long long node, long long parent, long long weight) {
  weights[node] = weight;
  long long size = 0;
  if (edges[node].size() == 1) size++;
  for (auto pa : edges[node]) {
    long long child = pa.first;
    if (child != parent) {
      size += dfs(child, node, pa.second);
    }
  }
  sizes[node] = size;
  current += size * weight;
  return size;
}
int main(int argn, char **argv) {
  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);
  int T = 1;
  cin >> T;
  for (int(I) = (0); (I) <= ((T)-1); (I)++) {
    current = 0;
    cin >> n >> s;
    edges = vector<vector<pair<long long, long long>>>(n + 5);
    weights = vector<long long>(n + 5, 0);
    sizes = vector<long long>(n + 5, 0);
    for (int(i) = (0); (i) <= ((n - 1) - 1); (i)++) {
      long long u, v, w;
      cin >> u >> v >> w;
      edges[u].emplace_back(v, w);
      edges[v].emplace_back(u, w);
    }
    dfs(1, -1, 0);
    ;
    ;
    ;
    priority_queue<pair<long long, long long>> pq;
    for (int(i) = (2); (i) <= (n); (i)++) {
      long long earning = (weights[i] + 1) / 2 * sizes[i];
      pq.emplace(earning, i);
    }
    long long ans = 0;
    while (current > s) {
      auto pa = pq.top();
      pq.pop();
      long long earning, node;
      tie(earning, node) = pa;
      ans++;
      current -= earning;
      weights[node] /= 2;
      long long newEarning = (weights[node] + 1) / 2 * sizes[node];
      pq.emplace(newEarning, node);
      ;
    };
    cout << ans << endl;
  }
  return 0;
}
