#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int XX[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int YY[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int N = 1e5 + 5;
vector<pair<int, int>> adj[N];
long long int outdg[N];
bool vist[N];
long long int cont[N];
int dfs(int node) {
  vist[node] = 1;
  outdg[node] = 0;
  bool f = 0;
  for (auto child : adj[node])
    if (!vist[child.first]) {
      f = 1;
      cont[child.first] = child.second;
      outdg[node] += dfs(child.first);
    }
  if (!f)
    return outdg[node] = 1;
  else
    return outdg[node];
}
void solve() {
  long long int n, s;
  cin >> n >> s;
  long long int sum = 0;
  long long int steps = 0;
  for (int i = 1; i <= n; i++) {
    vist[i] = 0;
    adj[i].clear();
    cont[i] = 0;
    outdg[i] = 0;
  }
  for (int i = 1; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  dfs(1);
  for (int i = 2; i <= n; i++) {
    if (!outdg[i]) outdg[i] = 1;
    long long int ad = (outdg[i] * cont[i]);
    sum += ad;
  }
  priority_queue<pair<long long int, long long int>> pq;
  for (long long int i = 2; i <= n; i++) {
    long long int diff = ((cont[i] * outdg[i]) - (cont[i] / 2 * outdg[i]));
    pq.push({diff, i});
  }
  while (sum > s) {
    pair<long long int, long long int> p = pq.top();
    pq.pop();
    sum -= p.first;
    long long int pos = p.second;
    cont[pos] /= 2;
    long long int newdiff =
        ((cont[pos] * outdg[pos]) - (cont[pos] / 2 * outdg[pos]));
    pq.push({newdiff, pos});
    steps++;
  }
  cout << steps << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
