#include <bits/stdc++.h>
using namespace std;
long long used[100001], f[100001], kq, sum, n, s, dl[100001];
vector<pair<long long, long long> > e[100001];
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               less<pair<long long, long long> > >
    pq;
void DFS(long long u, long long ts) {
  used[u] = 1;
  for (int i = 0; i < e[u].size(); i++) {
    long long v = e[u][i].second;
    long long w = e[u][i].first;
    if (used[v] == 0) {
      DFS(v, w);
      f[u] += f[v];
    }
  }
  sum += (f[u] * ts);
  dl[u] = (ts / 2);
  pq.push(pair<long long, long long>(f[u] * ts - f[u] * dl[u], u));
}
int main() {
  long long T, x, y, w;
  cin >> T;
  for (int o = 1; o <= T; o++) {
    kq = 0, sum = 0;
    cin >> n >> s;
    for (int i = 1; i < n; i++) {
      cin >> x >> y >> w;
      e[x].push_back(pair<long long, long long>(w, y));
      e[y].push_back(pair<long long, long long>(w, x));
    }
    for (int j = 1; j <= n; j++) {
      if (e[j].size() == 1) {
        f[j] = 1;
      }
    }
    DFS(1, 0);
    while (sum > s) {
      sum -= pq.top().first;
      y = pq.top().second;
      x = dl[y] / 2;
      pq.push(pair<long long, long long>((dl[y] * f[y] - f[y] * x), y));
      dl[y] = x;
      pq.pop();
      kq++;
    }
    while (!pq.empty()) {
      pq.pop();
    }
    for (int i = 1; i <= n; i++) {
      f[i] = 0;
      used[i] = 0;
      if (e[i].size() > 0) {
        e[i].clear();
      }
    }
    cout << kq << endl;
  }
}
