#include <bits/stdc++.h>
using namespace std;
int dfs(vector<pair<long long, long long>> tree[],
        multiset<pair<long long, pair<long long, long long>>>& values,
        long long root, vector<bool>& visited) {
  visited[root] = true;
  long long total = 0;
  if (root != 0 && tree[root].size() == 1) return 1;
  for (auto it = tree[root].begin(); it != tree[root].end(); it++) {
    if (!visited[it->first]) {
      long long val = dfs(tree, values, it->first, visited);
      long long gain = (it->second - it->second / 2) * val;
      values.insert({gain, {it->second, val}});
      total += val;
    }
  }
  return total;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, s;
    cin >> n >> s;
    multiset<pair<long long, pair<long long, long long>>> values;
    vector<pair<long long, long long>> tree[n];
    for (int i = 0; i < n - 1; i++) {
      long long u, v, w;
      cin >> u >> v >> w;
      u--;
      v--;
      tree[u].push_back({v, w});
      tree[v].push_back({u, w});
    }
    vector<bool> visited(n, false);
    dfs(tree, values, 0, visited);
    long long sum = 0;
    for (auto it = values.begin(); it != values.end(); it++)
      sum += (it->second).first * (it->second).second;
    int ans = 0;
    while (sum > s) {
      auto it = prev(values.end());
      sum -= it->first;
      long long newVal = (it->second).first / 2;
      long long gain = (newVal - newVal / 2) * (it->second).second;
      long long c = (it->second).second;
      values.erase(it);
      values.insert({gain, {newVal, c}});
      ans++;
    }
    cout << ans << "\n";
  }
  return 0;
}
