#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int MAXN = 100010;
struct Node {
  int v;
  LL dist, times;
  LL diff;
  bool operator<(const Node& t) const {
    if (diff != t.diff) return diff > t.diff;
    return v < t.v;
  }
};
LL s[MAXN];
vector<pair<int, LL>> x[MAXN];
LL sum;
set<Node> sums;
void Dfs(int a, int fa) {
  bool leaf = true;
  for (auto [b, c] : x[a]) {
    if (b == fa) continue;
    leaf = false;
    Dfs(b, a);
    s[a] += s[b];
    sum += s[b] * c;
    sums.insert({b, c, s[b], (c - c / 2) * s[b]});
  }
  if (leaf) s[a] = 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int times;
  cin >> times;
  while (times--) {
    int n;
    LL S;
    cin >> n >> S;
    for (int i = 1; i <= n; ++i) {
      x[i].clear();
      s[i] = 0;
    }
    for (int i = 1; i < n; ++i) {
      int a, b, c;
      cin >> a >> b >> c;
      x[a].push_back({b, c});
      x[b].push_back({a, c});
    }
    sum = 0;
    sums.clear();
    Dfs(1, -1);
    int count = 0;
    while (sum > S) {
      ++count;
      Node t = *sums.begin();
      sums.erase(sums.begin());
      sum -= t.dist * t.times;
      t.dist /= 2;
      sum += t.dist * t.times;
      t.diff = (t.dist - t.dist / 2) * t.times;
      sums.insert(t);
    }
    cout << count << endl;
  }
  return 0;
}
