#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 30;
const long long Mod = 998244353;
long long Quick_Power(long long a, long long b, long long c) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (1ll * ans * a) % c;
    a = (1ll * a * a) % c;
    b >>= 1;
  }
  return ans;
}
struct Node {
  int u, v;
  int t, id;
  long long w;
  long long val;
  bool operator<(const Node t) const { return val < t.val; }
} e[Maxn];
int son[Maxn];
vector<int> ve[Maxn];
int f[Maxn];
int de[Maxn];
void dfs(int s, int fa) {
  if (ve[s].size() == 1 && f[s] != -1) son[s] = 1;
  for (int i = 0; i < ve[s].size(); i++) {
    int to = ve[s][i];
    if (to != fa) {
      f[to] = s;
      dfs(to, s);
      son[s] += son[to];
    }
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    long long s;
    scanf("%d%lld", &n, &s);
    for (int i = 1; i <= n; i++) {
      ve[i].clear();
      son[i] = 0;
      f[i] = 0;
      de[i] = 0;
    }
    for (int i = 1; i <= n - 1; i++) {
      int u, v;
      long long w;
      scanf("%d%d%lld", &u, &v, &w);
      ve[u].push_back(v);
      ve[v].push_back(u);
      e[i].id = i;
      e[i].u = u;
      e[i].v = v;
      e[i].w = w;
    }
    dfs(1, -1);
    f[1] = -1;
    priority_queue<Node> q;
    long long sum = 0;
    for (int i = 1; i <= n - 1; i++) {
      if (f[e[i].u] == e[i].v) {
        int temp = e[i].u;
        e[i].u = e[i].v;
        e[i].v = temp;
      }
      if (e[i].w % 2 == 1)
        e[i].val = e[i].w * son[e[i].v] - (e[i].w - 1) * son[e[i].v] / 2;
      else
        e[i].val = e[i].w * son[e[i].v] / 2;
      q.push(e[i]);
      sum += e[i].w * son[e[i].v];
    }
    long long ans = 0;
    while (sum > s) {
      Node temp = q.top();
      Node newn;
      q.pop();
      sum -= temp.val;
      newn.id = temp.id;
      newn.u = temp.u;
      newn.v = temp.v;
      newn.w = temp.w / 2;
      if (newn.w % 2 == 1)
        newn.val = newn.w * son[newn.v] - (newn.w - 1) * son[newn.v] / 2;
      else
        newn.val = newn.w * son[newn.v] / 2;
      q.push(newn);
      ans++;
    }
    printf("%lld\n", ans);
  }
}
