#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const int MOD = 1000000007;
const long long INF = 1e18;
const int MX = 100001;
const double epsilon = 1e-12;
const int ds[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
vector<pair<long long, long long>> cm[100005];
int child[100005];
priority_queue<pair<long long, pair<long long, long long>>,
               vector<pair<long long, pair<long long, long long>>>,
               less<pair<long long, pair<long long, long long>>>>
    pq;
long long csum;
void dfs(int u, int par) {
  for (auto v : cm[u]) {
    if (v.first == par) continue;
    dfs(v.first, u);
    child[u] += child[v.first];
    long long diff = (v.second - v.second / 2) * child[v.first];
    pq.push(make_pair(diff, make_pair(child[v.first], v.second)));
    csum += v.second * child[v.first];
  }
  if (child[u] == 0) child[u] = 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int o = 0; o < t; o++) {
    int n;
    long long w;
    cin >> n >> w;
    memset(cm, 0, sizeof cm);
    memset(child, 0, sizeof child);
    pq = priority_queue<pair<long long, pair<long long, long long>>,
                        vector<pair<long long, pair<long long, long long>>>,
                        less<pair<long long, pair<long long, long long>>>>();
    csum = 0;
    for (int i = 0; i < n - 1; i++) {
      long long n1, n2, n3;
      cin >> n1 >> n2 >> n3;
      cm[n1].push_back(make_pair(n2, n3));
      cm[n2].push_back(make_pair(n1, n3));
    }
    dfs(1, -1);
    int c = 0;
    while (csum > w) {
      auto u = pq.top();
      pq.pop();
      if (u.first == 0) continue;
      csum -= u.first;
      u.second.second /= 2;
      long long diff = (u.second.second - u.second.second / 2) * u.second.first;
      pq.push(make_pair(diff, make_pair(u.second.first, u.second.second)));
      c++;
    }
    printf("%d\n", c);
  }
  return 0;
}
