#include <bits/stdc++.h>
using namespace std;
bool iseven(long long n) {
  if (n % 2 == 0)
    return true;
  else {
    return false;
  }
}
vector<long long> position(long long a) {
  vector<long long> p(30, 0);
  long double x = a;
  int i = 0;
  while (a > 0) {
    if ((a & 1) == 1)
      p[i] = 1;
    else {
      p[i] = 0;
    }
    a = a >> 1;
    i++;
  }
  return p;
}
long long power(long long x, unsigned long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
void print(vector<long long> a, long long n) {
  for (int i = 0; i < n; i += 1) cout << a[i] << " ";
  cout << "\n";
}
bool sec(const pair<long long, long long> &a,
         const pair<long long, long long> &b) {
  if (a.first == b.first)
    return (a.second > b.second);
  else {
    return (a.first > b.first);
  }
}
vector<long long> suffixsum(vector<long long> &a, long long n) {
  vector<long long> pre(n, 0);
  pre[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    pre[i] = pre[i + 1] + a[i];
  }
  return pre;
}
vector<long long> preffixsum(vector<long long> &a, long long n) {
  vector<long long> pre(n, 0);
  pre[0] = a[0];
  for (int i = 1; i < n; i++) {
    pre[i] = pre[i - 1] + a[i];
  }
  return pre;
}
long long dfs(vector<vector<pair<long long, long long>>> &adj,
              vector<long long> &v, vector<pair<long long, long long>> &f,
              int s) {
  v[s] = 1;
  long long t = 0;
  for (auto u : adj[s]) {
    if (v[u.first] == 0) {
      v[u.first] = 1;
      long long d = (dfs(adj, v, f, u.first));
      t += d;
      f.push_back({u.second, d});
    }
  }
  return max(t, 1ll);
}
long long can_remove(vector<pair<long long, long long>> &f, long long id) {
  long long k = f[id].first - ((f[id].first) / 2);
  return k * f[id].second;
}
void solve() {
  long long n, l;
  cin >> n >> l;
  priority_queue<pair<long long, long long>> h;
  long long ts = 0;
  vector<vector<pair<long long, long long>>> adj(n + 1);
  vector<long long> e, v(n + 1, 0);
  vector<pair<long long, long long>> f;
  for (long long i = 0; i < (n - 1); ++i) {
    long long x, y, z;
    cin >> x >> y >> z;
    adj[x].push_back({y, z});
    adj[y].push_back({x, z});
  }
  dfs(adj, v, f, 1);
  long long id = 0;
  for (auto i : f) {
    h.push({can_remove(f, id), id++});
    ts += (i.first * i.second);
  }
  long long ans = 0;
  while (ts > l) {
    auto pe = h.top();
    long long id = pe.second;
    h.pop();
    ts = ts - pe.first;
    f[id].first = (f[id].first) / 2;
    ans++;
    h.push({can_remove(f, id), id});
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
