#include <bits/stdc++.h>
using namespace std;
const long long INF64 = (long long)1e16;
const int INF = 1e9 + 500;
const int mod = (int)1e9 + 7;
int n;
long long s, cnt;
vector<vector<pair<int, int> > > adj;
vector<int> sz;
priority_queue<pair<long long, pair<int, int> > > pq;
void dfs(int u, int p) {
  bool is_leaf = 1;
  for (auto to : adj[u]) {
    if (to.first == p) continue;
    is_leaf = 0;
    dfs(to.first, u);
    sz[u] += sz[to.first];
    cnt = cnt + (long long)sz[to.first] * to.second;
    long long diff = (long long)sz[to.first] * to.second -
                     (long long)sz[to.first] * (to.second / 2);
    pq.push({diff, {to.second, sz[to.first]}});
  }
  if (is_leaf) sz[u] += 1;
}
void test_case() {
  cin >> n >> s;
  cnt = 0;
  adj.clear();
  sz.clear();
  while (pq.size()) pq.pop();
  adj.resize(n);
  sz.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  dfs(0, -1);
  int moves = 0;
  while (cnt > s) {
    auto t = pq.top();
    pq.pop();
    cnt = cnt - t.first;
    t.second.first = t.second.first / 2;
    long long diff = (long long)t.second.first * t.second.second -
                     (long long)t.second.second * (t.second.first / 2);
    pq.push({diff, {t.second.first, t.second.second}});
    moves += 1;
  }
  cout << moves << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) test_case();
}
