#include <bits/stdc++.h>
using namespace std;
void dfs(long long int node, vector<long long int>& visited,
         vector<vector<pair<long long int, long long int>>>& adj,
         vector<long long int>& count,
         priority_queue<pair<long long int, long long int>,
                        vector<pair<long long int, long long int>>>& pq,
         long long int& total) {
  long long int num = 0;
  visited[node] = 1;
  for (long long int i = 0; i < adj[node].size(); i++) {
    long long int j = adj[node][i].first;
    if (visited[j]) continue;
    num++;
    dfs(j, visited, adj, count, pq, total);
    pq.push(make_pair(count[j] * ((adj[node][i].second + 1) / 2),
                      adj[node][i].second));
    total += count[j] * adj[node][i].second;
    count[node] += count[j];
  }
  if (num == 0) {
    count[node] = 1;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, s;
    cin >> n >> s;
    vector<vector<pair<long long int, long long int>>> adj(n + 1);
    for (long long int i = 0; i < n - 1; i++) {
      long long int a, b, w;
      cin >> a >> b >> w;
      adj[a].push_back(make_pair(b, w));
      adj[b].push_back(make_pair(a, w));
    }
    vector<long long int> visited(n + 1, 0);
    vector<long long int> count(n + 1, 0);
    priority_queue<pair<long long int, long long int>,
                   vector<pair<long long int, long long int>>>
        pq;
    long long int total = 0;
    dfs(1, visited, adj, count, pq, total);
    long long int final = 0;
    while (total > s) {
      final++;
      pair<long long int, long long int> p = pq.top();
      pq.pop();
      total -= p.first;
      long long int num = (p.second + 1) / 2;
      long long int c = p.first / num;
      p.second = p.second / 2;
      p.first = c * ((p.second + 1) / 2);
      pq.push(p);
    }
    cout << final << endl;
  }
  return 0;
}
