#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 100005;
int n;
long long s;
vector<pair<int, int> > g[N];
struct ban {
  long long d;
  int q;
  ban() {
    d = 0;
    q = 0;
  }
};
bool operator<(const ban& a, const ban& b) {
  long long ua = (a.d / 2 + a.d % 2) * a.q;
  long long ub = (b.d / 2 + b.d % 2) * b.q;
  return ua < ub;
}
ban a[N];
void dfs0(int x, int p) {
  if (x == p) a[x].d = 0;
  if (((int)(g[x]).size()) == 1 && x != p)
    a[x].q = 1;
  else
    a[x].q = 0;
  for (int i = 0; i < g[x].size(); ++i) {
    int h = g[x][i].first;
    if (h == p) continue;
    a[h].d = g[x][i].second;
    dfs0(h, x);
    a[x].q += a[h].q;
  }
}
void solv() {
  scanf("%d%lld", &n, &s);
  for (int x = 1; x <= n; ++x) g[x].clear();
  for (int i = 0; i < n - 1; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  dfs0(1, 1);
  priority_queue<ban> q;
  for (int x = 1; x <= n; ++x) {
    s -= a[x].d * a[x].q;
    q.push(a[x]);
  }
  int ans = 0;
  while (s < 0) {
    ++ans;
    ban t = q.top();
    q.pop();
    s += (t.d / 2 + t.d % 2) * t.q;
    t.d /= 2;
    q.push(t);
  }
  printf("%d\n", ans);
}
int main() {
  int tt;
  scanf("%d", &tt);
  while (tt--) solv();
  return 0;
}
