#include <bits/stdc++.h>
using namespace std;
long long int n, s, ans, sum;
map<int, map<int, long long int>> edges;
multiset<vector<long long int>> values;
int DFS(int child, int parent) {
  int leaves = (edges[child].size() == 1);
  for (auto &c : edges[child])
    if (c.first != parent) {
      int ter = DFS(c.first, child);
      values.insert({c.second * ter - c.second / 2 * ter, c.second, ter});
      sum += c.second * ter;
      leaves += ter;
    }
  return leaves;
}
void findAns() {
  cin >> n >> s;
  for (int i = 0; i < n - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    edges[u][v] = edges[v][u] = w;
  }
  DFS(1, 0);
  while (sum > s) {
    ans++;
    auto it = *values.rbegin();
    values.erase(values.find(it));
    sum -= it[0];
    it[1] = it[1] / 2;
    it[0] = it[1] * it[2] - it[1] / 2 * it[2];
    values.insert(it);
  }
  cout << ans << "\n";
  values.clear();
  edges.clear();
  ans = sum = 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  long long int t = 1;
  cin >> t;
  for (int i = 1; i <= t; i++) findAns();
  return 0;
}
