#include <bits/stdc++.h>
using namespace std;
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
unordered_map<int, vector<pair<int, int>>> mp;
unordered_map<pair<int, int>, int, hash_pair> edg;
unordered_map<int, int> eiw;
std::vector<std::vector<int>> res;
void f(int u, int parent, std::vector<int> vec) {
  bool ff = false;
  for (auto p : mp[u]) {
    int v = p.first;
    if (v == parent) continue;
    ff = true;
    int ei = edg[{min(u, v), max(u, v)}];
    vec.push_back(ei);
    f(v, u, vec);
  }
  if (!ff) res.push_back(vec);
}
int main() {
  long long int t;
  cin >> t;
  for (long long int ts = 1; ts <= t; ts++) {
    mp.clear();
    edg.clear();
    eiw.clear();
    long long int n, s;
    cin >> n >> s;
    int x = 0;
    for (long long int i = 0; i < n - 1; i++) {
      int u, v, w;
      cin >> u >> v >> w;
      mp[u].push_back({v, w});
      mp[v].push_back({u, w});
      edg[{min(u, v), max(u, v)}] = x;
      eiw[x] = w;
      x++;
    }
    long long int ans = 0;
    unordered_map<int, int> ef;
    for (auto vv : res) {
      for (auto edge : vv) {
        if (ef.find(edge) == ef.end())
          ef[edge] = 1;
        else
          ef[edge]++;
      }
    }
    int cs = 0;
    priority_queue<pair<int, int>, std::vector<pair<int, int>>,
                   greater<pair<int, int>>>
        pq;
    for (auto it = ef.begin(); it != ef.end(); it++) {
      int edge = it->first;
      int wt = eiw[edge];
      int f = it->second;
      cs += (wt * f);
      pq.push({wt * f, wt});
    }
    if (cs <= s) {
      cout << "0" << endl;
      continue;
    }
    while (true) {
      pair<int, int> pr = pq.top();
      pq.pop();
      int wt = pr.second;
      int sum = pr.first;
      int f = sum / wt;
      wt = wt / 2;
      int new_sum = f * wt;
      int diff = sum - new_sum;
      cs -= diff;
      ans++;
      if (cs <= s) {
        cout << ans << endl;
        break;
      }
      pq.push({new_sum, wt});
    }
  }
  return 0;
}
