#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
void debug3(int *t,int st,int n) {cerr << '{' << t[st];for(int i=st+1;i<=n;i++) cerr<<",",__print(t[i]);cerr <<"}"<<'\n';}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debug2(x...) cerr<<"[" << #x << "] = "; debug3(x)
#endif

#define N 100005
#define MOD 998244353
#define ll long long int
#define ull unsigned long long
#define pii pair<int,int>
#define sf second.first
#define ss second.second

int lf[N] ;
ll sm ,ssf;
multiset<pair<int,pii> > s;
vector<pii> graf[N];

void dfs(int nod,int tt)
{
    if ( graf[nod].size() == 1 )
        lf[nod] = 1 ;
    for ( auto vec : graf[nod] )
    {
        if ( vec.first == tt )
            continue ;
        dfs(vec.first,nod) ;
        lf[nod] += lf[vec.first] ;
        ll kk = lf[vec.first]*vec.second ;
        sm = sm+kk;
        s.insert({lf[vec.first]*vec.second-vec.second/2*lf[vec.first],{lf[vec.first],vec.second}}) ;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.in", "r", stdin);
    int t , n , i ,x,y,z,sol;
    cin >> t ;
    while ( t-- )
    {
        cin >> n >> ssf ;
        for ( i = 1 ; i < n ; i++ )
        {
            cin >> x >> y >> z ;
            graf[x].push_back({y,z}) ;
            graf[y].push_back({x,z}) ;
        }
        dfs(1,0);
        sol = 0 ;
        while ( sm > ssf )
        {
            auto v = *s.rbegin() ;
            s.erase(prev(s.end()));
            sm -= v.first ;
            v.ss /= 2 ;
            v.first = v.sf*v.ss - v.ss/2*v.sf;
            s.insert(v) ;
            sol++;
        }
        cout << sol << '\n' ;
        s.clear() ;
        for ( i = 1 ; i <= n ; i++ )
            graf[i].clear() , lf[i] = 0 ;
        sm = 0 ;
    }
}


#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
void debug3(int *t,int st,int n) {cerr << '{' << t[st];for(int i=st+1;i<=n;i++) cerr<<",",__print(t[i]);cerr <<"}"<<'\n';}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debug2(x...) cerr<<"[" << #x << "] = "; debug3(x)
#endif

#define N 100005
#define MOD 998244353
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define sf second.first
#define ss second.second

ll sm ,ssf;
multiset<vector<ll> > s;
map<int,map<int,ll> > mp;

int dfs(int nod,int tt)
{
    int x = 0;
    if ( mp[nod].size() == 1 )
        x = 1 ;
    for ( auto vec : mp[nod] )
    {
        if ( vec.first == tt )
            continue ;
        int p = dfs(vec.first,nod) ;
        x = x+p;
        sm += p * vec.second ;
        s.insert({p*vec.second-vec.second/2*p,p,vec.second}) ;
    }
    return x;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.in", "r", stdin);
    int t , n , i ,x,y,z,sol;
    cin >> t ;
    while ( t-- )
    {
        cin >> n >> ssf ;
        for ( i = 1 ; i < n ; i++ )
        {
            cin >> x >> y >> z ;
            mp[x][y] = z;
            mp[y][x] = z;
        }
        dfs(1,0);
        sol = 0 ;
        while ( sm > ssf )
        {
            auto v = *s.rbegin() ;
            s.erase(prev(s.end()));
            sm -= v[0] ;
            v[2] /= 2 ;
            v[0] = v[1]*v[2]- v[2]/2*v[1];
            s.insert(v) ;
            sol++;
        }
        cout << sol << '\n' ;
        s.clear() ;
        mp.clear();
        sm = 0 ;
    }
}


#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
void debug3(int *t,int st,int n) {cerr << '{' << t[st];for(int i=st+1;i<=n;i++) cerr<<",",__print(t[i]);cerr <<"}"<<'\n';}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debug2(x...) cerr<<"[" << #x << "] = "; debug3(x)
#endif

#define N 100005
#define MOD 998244353
#define ll long long int
#define ull unsigned long long
#define pii pair<int,int>
#define sf second.first
#define ss second.second

int lf[N] ;
ll sm ,ssf;
multiset<pair<int,pii> > s;
vector<pii> graf[N];

void dfs(int nod,int tt)
{
    if ( graf[nod].size() == 1 )
        lf[nod] = 1 ;
    for ( auto vec : graf[nod] )
    {
        if ( vec.first == tt )
            continue ;
        dfs(vec.first,nod) ;
        lf[nod] += lf[vec.first] ;
        ll kk = 1LL*lf[vec.first]*vec.second ;
        sm = sm+kk;
        s.insert({lf[vec.first]*vec.second-vec.second/2*lf[vec.first],{lf[vec.first],vec.second}}) ;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.in", "r", stdin);
    int t , n , i ,x,y,z,sol;
    cin >> t ;
    while ( t-- )
    {
        cin >> n >> ssf ;
        for ( i = 1 ; i < n ; i++ )
        {
            cin >> x >> y >> z ;
            graf[x].push_back({y,z}) ;
            graf[y].push_back({x,z}) ;
        }
        dfs(1,0);
        sol = 0 ;
        while ( sm > ssf )
        {
            auto v = *s.rbegin() ;
            s.erase(prev(s.end()));
            sm -= v.first ;
            v.ss /= 2 ;
            v.first = v.sf*v.ss - v.ss/2*v.sf;
            s.insert(v) ;
            sol++;
        }
        cout << sol << '\n' ;
        s.clear() ;
        for ( i = 1 ; i <= n ; i++ )
            graf[i].clear() , lf[i] = 0 ;
        sm = 0 ;
    }
}


#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
void debug3(int *t,int st,int n) {cerr << '{' << t[st];for(int i=st+1;i<=n;i++) cerr<<",",__print(t[i]);cerr <<"}"<<'\n';}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debug2(x...) cerr<<"[" << #x << "] = "; debug3(x)
#endif

#define N 100005
#define MOD 998244353
#define ll long long int
#define ull unsigned long long
#define pii pair<int,int>
#define sf second.first
#define ss second.second

ll sm ,ssf;
multiset<pair<int,pii> > s;
map<int,map<int,ll> > mp;

int dfs(int nod,int tt)
{
    int x = 0;
    if ( mp[nod].size() == 1 )
        x = 1 ;
    for ( auto vec : mp[nod] )
    {
        if ( vec.first == tt )
            continue ;
        int p = dfs(vec.first,nod) ;
        x = x+p;
        sm += p * vec.second ;
        s.insert({p*vec.second-vec.second/2*p,{p,vec.second}}) ;
    }
    return x;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.in", "r", stdin);
    int t , n , i ,x,y,z,sol;
    cin >> t ;
    while ( t-- )
    {
        cin >> n >> ssf ;
        for ( i = 1 ; i < n ; i++ )
        {
            cin >> x >> y >> z ;
            mp[x][y] = z;
            mp[y][x] = z;
        }
        dfs(1,0);
        sol = 0 ;
        while ( sm > ssf )
        {
            auto v = *s.rbegin() ;
            s.erase(prev(s.end()));
            sm -= v.first ;
            v.ss /= 2 ;
            v.first = v.sf*v.ss - v.ss/2*v.sf;
            s.insert(v) ;
            sol++;
        }
        cout << sol << '\n' ;
        s.clear() ;
        mp.clear();
        sm = 0 ;
    }
}


#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
void debug3(int *t,int st,int n) {cerr << '{' << t[st];for(int i=st+1;i<=n;i++) cerr<<",",__print(t[i]);cerr <<"}"<<'\n';}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debug2(x...) cerr<<"[" << #x << "] = "; debug3(x)
#endif

#define N 100005
#define MOD 998244353
#define ll long long int
#define ull unsigned long long
#define pii pair<int,int>
#define sf second.first
#define ss second.second

int lf[N] ;
ll sm ;
multiset<pair<int,pii> > s;
vector<pii> graf[N];

void dfs(int nod,int tt)
{
    if ( graf[nod].size() == 1 )
        lf[nod] = 1 ;
    for ( auto vec : graf[nod] )
    {
        if ( vec.first == tt )
            continue ;
        dfs(vec.first,nod) ;
        lf[nod] += lf[vec.first] ;
        sm += 1LL*lf[vec.first]*vec.second ;
        s.insert({lf[vec.first]*vec.second-vec.second/2*lf[vec.first],{lf[vec.first],vec.second}}) ;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.in", "r", stdin);
    int t , n , i ,x,y,z,sol;
    ll ssf ;
    cin >> t ;
    while ( t-- )
    {
        cin >> n >> ssf ;
        for ( i = 1 ; i < n ; i++ )
        {
            cin >> x >> y >> z ;
            graf[x].push_back({y,z}) ;
            graf[y].push_back({x,z}) ;
        }
        dfs(1,0);
        sol = 0 ;
        while ( sm > ssf )
        {
            auto v = *s.rbegin() ;
            s.erase(prev(s.end()));
            sm -= v.first ;
            v.ss /= 2 ;
            v.first = v.sf*v.ss - v.ss/2*v.sf;
            s.insert(v) ;
            sol++;
        }
        cout << sol << '\n' ;
        s.clear() ;
        for ( i = 1 ; i <= n ; i++ )
            graf[i].clear() , lf[i] = 0 ;
        sm = 0 ;
    }
}


#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
void debug3(int *t,int st,int n) {cerr << '{' << t[st];for(int i=st+1;i<=n;i++) cerr<<",",__print(t[i]);cerr <<"}"<<'\n';}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debug2(x...) cerr<<"[" << #x << "] = "; debug3(x)
#endif

#define N 100005
#define MOD 998244353
#define ll long long int
#define ull unsigned long long
#define pii pair<int,int>
#define sf second.first
#define ss second.second

int lf[N] ;
ll sm ,ssf;
multiset<pair<int,pii> > s;
vector<pii> graf[N];

void dfs(int nod,int tt)
{
    if ( graf[nod].size() == 1 )
        lf[nod] = 1 ;
    for ( auto vec : graf[nod] )
    {
        if ( vec.first == tt )
            continue ;
        dfs(vec.first,nod) ;
        lf[nod] += lf[vec.first] ;
        sm += lf[vec.first]*vec.second ;
        s.insert({lf[vec.first]*vec.second-vec.second/2*lf[vec.first],{lf[vec.first],vec.second}}) ;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.in", "r", stdin);
    int t , n , i ,x,y,z,sol;
    cin >> t ;
    while ( t-- )
    {
        cin >> n >> ssf ;
        for ( i = 1 ; i < n ; i++ )
        {
            cin >> x >> y >> z ;
            graf[x].push_back({y,z}) ;
            graf[y].push_back({x,z}) ;
        }
        dfs(1,0);
        sol = 0 ;
        while ( sm > ssf )
        {
            auto v = *s.rbegin() ;
            s.erase(prev(s.end()));
            sm -= v.first ;
            v.ss /= 2 ;
            v.first = v.sf*v.ss - v.ss/2*v.sf;
            s.insert(v) ;
            sol++;
        }
        cout << sol << '\n' ;
        s.clear() ;
        for ( i = 1 ; i <= n ; i++ )
            graf[i].clear() , lf[i] = 0 ;
        sm = 0 ;
    }
}


#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
void debug3(int *t,int st,int n) {cerr << '{' << t[st];for(int i=st+1;i<=n;i++) cerr<<",",__print(t[i]);cerr <<"}"<<'\n';}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debug2(x...) cerr<<"[" << #x << "] = "; debug3(x)
#endif

#define N 100005
#define MOD 998244353
#define ll long long int
#define ull unsigned long long
#define pii pair<int,int>
#define sf second.first
#define ss second.second

int lf[N] ;
ll sm ,ssf;
multiset<pair<int,pii> > s;
vector<pair<int,ll> > graf[N];

void dfs(int nod,int tt)
{
    if ( graf[nod].size() == 1 )
        lf[nod] = 1 ;
    for ( auto vec : graf[nod] )
    {
        if ( vec.first == tt )
            continue ;
        dfs(vec.first,nod) ;
        lf[nod] += lf[vec.first] ;
        sm += lf[vec.first]*vec.second ;
        s.insert({lf[vec.first]*vec.second-vec.second/2*lf[vec.first],{lf[vec.first],vec.second}}) ;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    /*cin.tie(0);
    cout.tie(0);*/
    //freopen("test.in", "r", stdin);
    int t , n , i ,x,y,z,sol;
    scanf("%d",&t);
    while ( t-- )
    {
        scanf("%d %ull",&n,&ssf);
        for ( i = 1 ; i < n ; i++ )
        {
            scanf("%d %d %d",&x,&y,&z);
            graf[x].push_back({y,z}) ;
            graf[y].push_back({x,z}) ;
        }
        dfs(1,0);
        sol = 0 ;
        while ( sm > ssf )
        {
            auto v = *s.rbegin() ;
            s.erase(prev(s.end()));
            sm -= v.first ;
            v.ss /= 2 ;
            v.first = v.sf*v.ss - v.ss/2*v.sf;
            s.insert(v) ;
            sol++;
        }
        printf("%d\n",sol);
        s.clear() ;
        for ( i = 1 ; i <= n ; i++ )
            graf[i].clear() , lf[i] = 0 ;
        sm = 0 ;
    }
}


#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
void debug3(int *t,int st,int n) {cerr << '{' << t[st];for(int i=st+1;i<=n;i++) cerr<<",",__print(t[i]);cerr <<"}"<<'\n';}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debug2(x...) cerr<<"[" << #x << "] = "; debug3(x)
#endif

#define N 100005
#define MOD 998244353
#define ll long long int
#define ull unsigned long long
#define pii pair<int,int>
#define sf second.first
#define ss second.second

int lf[N] ;
ll sm ;
multiset<pair<int,pair<int,ll> > > s;
vector<pair<int,ll> > graf[N];

void dfs(int nod,int tt)
{
    if ( graf[nod].size() == 1 )
        lf[nod] = 1 ;
    for ( auto vec : graf[nod] )
    {
        if ( vec.first == tt )
            continue ;
        dfs(vec.first,nod) ;
        lf[nod] += lf[vec.first] ;
        sm += lf[vec.first]*vec.second ;
        s.insert({lf[vec.first]*(vec.second-vec.second/2),{lf[vec.first],vec.second}}) ;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.in", "r", stdin);
    int t , n , i ,x,y,z,sol;
    ll ssf ;
    cin >> t ;
    while ( t-- )
    {
        cin >> n >> ssf ;
        for ( i = 1 ; i < n ; i++ )
        {
            cin >> x >> y >> z ;
            graf[x].push_back({y,z}) ;
            graf[y].push_back({x,z}) ;
        }
        dfs(1,0);
        sol = 0 ;
        while ( sm > ssf )
        {
            auto v = *s.rbegin() ;
            s.erase(prev(s.end()));
            sm -= v.first ;
            v.ss /= 2 ;
            v.first = v.sf*v.ss - v.ss/2*v.sf;
            s.insert(v) ;
            sol++;
        }
        cout << sol << '\n' ;
        s.clear() ;
        for ( i = 1 ; i <= n ; i++ )
            graf[i].clear() , lf[i] = 0 ;
        sm = 0 ;
    }
}


#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
void debug3(int *t,int st,int n) {cerr << '{' << t[st];for(int i=st+1;i<=n;i++) cerr<<",",__print(t[i]);cerr <<"}"<<'\n';}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debug2(x...) cerr<<"[" << #x << "] = "; debug3(x)
#endif

#define N 100005
#define MOD 998244353
#define ll long long int
#define ull unsigned long long
#define pii pair<int,int>
#define sf second.first
#define ss second.second

int lf[N] ;
ll sm ;
multiset<pair<int,pii> > s;
vector<pii> graf[N];

void dfs(int nod,int tt)
{
    if ( graf[nod].size() == 1 )
        lf[nod] = 1 ;
    for ( auto vec : graf[nod] )
    {
        if ( vec.first == tt )
            continue ;
        dfs(vec.first,nod) ;
        lf[nod] += lf[vec.first] ;
        sm += lf[vec.first]*vec.second ;
        s.insert({lf[vec.first]*vec.second-vec.second/2*lf[vec.first],{lf[vec.first],vec.second}}) ;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.in", "r", stdin);
    int t , n , i ,x,y,z,sol;
    ll ssf ;
    cin >> t ;
    while ( t-- )
    {
        cin >> n >> ssf ;
        for ( i = 1 ; i < n ; i++ )
        {
            cin >> x >> y >> z ;
            graf[x].push_back({y,z}) ;
            graf[y].push_back({x,z}) ;
        }
        dfs(1,0);
        sol = 0 ;
        while ( sm > ssf )
        {
            auto v = *s.rbegin() ;
            s.erase(prev(s.end()));
            sm -= v.first ;
            v.ss /= 2 ;
            v.first = v.sf*v.ss - v.ss/2*v.sf;
            s.insert(v) ;
            sol++;
        }
        cout << sol << '\n' ;
        s.clear() ;
        for ( i = 1 ; i <= n ; i++ )
            graf[i].clear() , lf[i] = 0 ;
        sm = 0 ;
    }
}


#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
void debug3(int *t,int st,int n) {cerr << '{' << t[st];for(int i=st+1;i<=n;i++) cerr<<",",__print(t[i]);cerr <<"}"<<'\n';}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debug2(x...) cerr<<"[" << #x << "] = "; debug3(x)
#endif

#define N 100005
#define MOD 998244353
#define ll long long int
#define ull unsigned long long
#define pii pair<int,int>
#define sf second.first
#define ss second.second

ll lf[N] , sm ;
set<tuple<ll,ll,ll> > s;
vector<pair<ll,ll> > graf[N];

void dfs(int nod,int tt)
{
    if ( graf[nod].size() == 1 )
        lf[nod] = 1 ;
    for ( auto vec : graf[nod] )
    {
        if ( vec.first == tt )
            continue ;
        dfs(vec.first,nod) ;
        lf[nod] += lf[vec.first] ;
        sm += lf[vec.first]*vec.second ;
        s.insert(make_tuple(lf[vec.first]*(vec.second-vec.second/2),lf[vec.first],vec.second)) ;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.in", "r", stdin);
    ll t , n , i , ssf,x,y,z,sol;
    cin >> t ;
    while ( t-- )
    {
        cin >> n >> ssf ;
        for ( i = 1 ; i < n ; i++ )
        {
            cin >> x >> y >> z ;
            graf[x].push_back({y,z}) ;
            graf[y].push_back({x,z}) ;
        }
        dfs(1,0);
        sol = 0 ;
        while ( sm > ssf )
        {
            auto v = *s.rbegin() ;
            s.erase(v);
            sm -= get<0>(v) ;
            get<2>(v) /= 2 ;
            get<0>(v) = get<1>(v)*get<2>(v) - get<2>(v)/2*get<1>(v);
            s.insert(v) ;
            sol++;
        }
        cout << sol << '\n' ;
        s.clear() ;
        for ( i = 1 ; i <= n ; i++ )
            graf[i].clear() , lf[i] = 0 ;
        sm = 0 ;
    }
}


#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
void debug3(int *t,int st,int n) {cerr << '{' << t[st];for(int i=st+1;i<=n;i++) cerr<<",",__print(t[i]);cerr <<"}"<<'\n';}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#define debug2(x...) cerr<<"[" << #x << "] = "; debug3(x)
#endif

#define N 100005
#define MOD 998244353
#define ll long long int
#define ull unsigned long long
#define pii pair<int,int>
#define sf second.first
#define ss second.second

ll sm ,ssf;
multiset<pair<int,pii> > s;
vector<pair<int,ll> > graf[N];

int dfs(int nod,int tt)
{
    int x = 0;
    if ( graf[nod].size() == 1 )
        x = 1 ;
    for ( auto vec : graf[nod] )
    {
        if ( vec.first == tt )
            continue ;
        int p = dfs(vec.first,nod) ;
        x = x+p;
        sm += p * vec.second ;
        s.insert({p*vec.second-vec.second/2*p,{p,vec.second}}) ;
    }
    return x;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.in", "r", stdin);
    int t , n , i ,x,y,z,sol;
    cin >> t ;
    while ( t-- )
    {
        cin >> n >> ssf ;
        for ( i = 1 ; i < n ; i++ )
        {
            cin >> x >> y >> z ;
            graf[x].push_back({y,z}) ;
            graf[y].push_back({x,z}) ;
        }
        dfs(1,0);
        sol = 0 ;
        while ( sm > ssf )
        {
            auto v = *s.rbegin() ;
            s.erase(prev(s.end()));
            sm -= v.first ;
            v.ss /= 2 ;
            v.first = v.sf*v.ss - v.ss/2*v.sf;
            s.insert(v) ;
            sol++;
        }
        cout << sol << '\n' ;
        if ( t )
        {
            s.clear() ;
            for ( i = 1 ; i <= n ; i++ )
                graf[i].clear() ;
            sm = 0 ;
        }
    }
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const array <ll,2> &a, const array <ll,2> &b) const {
		return a[0]-((a[0]/a[1])/2)*a[1]>b[0]-((b[0]/b[1])/2)*a[1];
	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e5+5;
set < array<ll,2> , cmp > s;
vector <ll> st(N);
vector <vector <array <ll,2> > >vec(N);

ll dfs(ll e, ll p){
    bool f=1;
    ll a=0;
    for(auto x : vec[e]){
        if(x[0]==p) continue;
        f=0;
        a+=dfs(x[0],e);
        s.insert({st[x[0]]*x[1],st[x[0]]});
    }
    if(f) st[e]=1;
    else st[e]=a;
    return st[e];
}

int main(){
    IOS;
    make(ll,t);
    while(t--){
        s.clear();
        make2(ll,n,q);
        fr(i,n) vec[i].clear();
        fr(i,n) st[i]=0;
        fr(i,n-1){
            make2(ll,x,y); make(ll,a);
            vec[--x].push_back({--y,a});
            vec[y].push_back({x,a});
        }
        dfs(0,-1);
        ll ss=0;
     //   cout<<s.size()<<"dd"<<endl;
        for(auto x : s){
            ss+=x[0];
           // cout<<x<<endl;
        }
        ll ans=0;
       // fr(i,n) cout<<st[i]<<" ";
      //  cout<<endl;

        while(ss>q){
            if(!s.size()) break;
            auto p=*s.begin();
            ss-=p[0];
            p[0]/=p[1]; p[0]/=2; p[0]*=p[1];
            ss+=p[0];
           // cout<<ss<<"a"<<endl;
            s.erase(s.begin());
            s.insert(p);
            ans++;
        }
        cout<<ans<<endl;

    }

// 1 5 10 1 2 20 1 3 20 2 4 10 2 5 10
    return 0;
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e5+5;
multiset <ll, greater <ll> > s;
vector <ll> st(N);
vector <vector <array <ll,2> > >vec(N);

ll dfs(ll e, ll p){
    bool f=1;
    ll a=0;
    for(auto x : vec[e]){
        if(x[0]==p) continue;
        f=0;
        a+=dfs(x[0],e);
        s.insert(st[x[0]]*x[1]);
    }
    if(f) st[e]=1;
    else st[e]=a;
    return st[e];
}

int main(){
    IOS;
    make(ll,t);
    while(t--){
        s.clear();
        make2(ll,n,q);
        fr(i,n) vec[i].clear();
        fr(i,n) st[i]=0;
        fr(i,n-1){
            make2(ll,x,y); make(ll,a);
            vec[--x].push_back({--y,a});
            vec[y].push_back({x,a});
        }
        dfs(0,-1);
        ll ss=0;
     //   cout<<s.size()<<"dd"<<endl;
        for(auto x : s){
            ss+=x;
           // cout<<x<<endl;
        }
        ll ans=0;
       // fr(i,n) cout<<st[i]<<" ";
      //  cout<<endl;
      if(ss<=q) cout<<"0 \n";
      else{
        while(ss>q){
            if(!s.size()) break;
            ll p=*s.begin();
            ss-=p; p/=2; ss+=p;
           // cout<<ss<<"a"<<endl;
            s.erase(s.begin());
            s.insert(p);
            ans++;
        }
        cout<<ans<<endl;
      }

    }

// 1 5 10 1 2 20 1 3 20 2 4 10 2 5 10
    return 0;
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e5+5;
multiset < array<ll,2> , greater <array <ll,2> > > s;
vector <ll> st(N);
vector <vector <array <ll,2> > >vec(N);

ll dfs(ll e, ll p){
    bool f=1;
    ll a=0;
    for(auto x : vec[e]){
        if(x[0]==p) continue;
        f=0;
        a+=dfs(x[0],e);
        s.insert({st[x[0]]*x[1],st[x[0]]});
    }
    if(f) st[e]=1;
    else st[e]=a;
    return st[e];
}

int main(){
    IOS;
    make(ll,t);
    while(t--){
        s.clear();
        make2(ll,n,q);
        fr(i,n) vec[i].clear();
        fr(i,n) st[i]=0;
        fr(i,n-1){
            make2(ll,x,y); make(ll,a);
            vec[--x].push_back({--y,a});
            vec[y].push_back({x,a});
        }
        dfs(0,-1);
        ll ss=0;
     //   cout<<s.size()<<"dd"<<endl;
        for(auto x : s){
            ss+=x[0];
           // cout<<x<<endl;
        }
        ll ans=0;
       // fr(i,n) cout<<st[i]<<" ";
      //  cout<<endl;

        while(ss>q){
            if(!s.size()) break;
            auto p=*s.begin();
            ss-=p[0];
            p[0]/=p[1]; p[0]/=2; p[0]*=p[1];
            ss+=p[0];
           // cout<<ss<<"a"<<endl;
            s.erase(s.begin());
            s.insert(p);
            ans++;
        }
        cout<<ans<<endl;

    }

// 1 5 10 1 2 20 1 3 20 2 4 10 2 5 10
    return 0;
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}
ll N=1e5+5;
vector <ll> st(N);
struct cmp {
	bool operator() (const array <ll,2> &a, const array <ll,2> &b) const {
		return a[0]-((a[0]/st[a[1]])/2)*st[a[1]]>b[0]-((b[0]/st[b[1]])/2)*st[b[1]];
	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};

multiset < array<ll,2> , cmp > s;

vector <vector <array <ll,2> > >vec(N);

ll dfs(ll e, ll p){
    bool f=1;
    ll a=0;
    for(auto x : vec[e]){
        if(x[0]==p) continue;
        f=0;
        a+=dfs(x[0],e);
        s.insert({st[x[0]]*x[1],x[0]});
    }
    if(f) st[e]=1;
    else st[e]=a;
    return st[e];
}

int main(){
    IOS;
    make(ll,t);
    while(t--){
        s.clear();
        make2(ll,n,q);
        fr(i,n) vec[i].clear();
        fr(i,n) st[i]=0;
        fr(i,n-1){
            make2(ll,x,y); make(ll,a);
            vec[--x].push_back({--y,a});
            vec[y].push_back({x,a});
        }
        dfs(0,-1);
        ll ss=0;
     //   cout<<s.size()<<"dd"<<endl;
        for(auto x : s){
            ss+=x[0];
           // cout<<x<<endl;
        }
        ll ans=0;
       // fr(i,n) cout<<st[i]<<" ";
      //  cout<<endl;

        while(ss>q){
            if(!s.size()) break;
            auto p=*s.begin();
            ss-=p[0];
            p[0]/=st[p[1]]; p[0]/=2; p[0]*=st[p[1]];
            ss+=p[0];
           // cout<<ss<<"a"<<endl;
            s.erase(s.begin());
            s.insert(p);
            ans++;
        }
        cout<<ans<<endl;

    }

// 1 5 10 1 2 20 1 3 20 2 4 10 2 5 10
    return 0;
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const array <ll,2> &a, const array <ll,2> &b) const {
		return a[0]-((a[0]/a[1])/2)*a[1]>b[0]-((b[0]/b[1])/2)*b[1];
	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e5+5;
set < array<ll,2> , cmp > s;
vector <ll> st(N);
vector <vector <array <ll,2> > >vec(N);

ll dfs(ll e, ll p){
    bool f=1;
    ll a=0;
    for(auto x : vec[e]){
        if(x[0]==p) continue;
        f=0;
        a+=dfs(x[0],e);
        s.insert({st[x[0]]*x[1],st[x[0]]});
    }
    if(f) st[e]=1;
    else st[e]=a;
    return st[e];
}

int main(){
    IOS;
    make(ll,t);
    while(t--){
        s.clear();
        make2(ll,n,q);
        fr(i,n) vec[i].clear();
        fr(i,n) st[i]=0;
        fr(i,n-1){
            make2(ll,x,y); make(ll,a);
            vec[--x].push_back({--y,a});
            vec[y].push_back({x,a});
        }
        dfs(0,-1);
        ll ss=0;
     //   cout<<s.size()<<"dd"<<endl;
        for(auto x : s){
            ss+=x[0];
           // cout<<x<<endl;
        }
        ll ans=0;
       // fr(i,n) cout<<st[i]<<" ";
      //  cout<<endl;

        while(ss>q){
            if(!s.size()) break;
            auto p=*s.begin();
            ss-=p[0];
            p[0]/=p[1]; p[0]/=2; p[0]*=p[1];
            ss+=p[0];
           // cout<<ss<<"a"<<endl;
            s.erase(s.begin());
            s.insert(p);
            ans++;
        }
        cout<<ans<<endl;

    }

// 1 5 10 1 2 20 1 3 20 2 4 10 2 5 10
    return 0;
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const array <ll,2> &a, const array <ll,2> &b) const {

	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e5+5;
vector <vector <array <ll,2> > >vec(N);
vector <ll> sl(N);
vector <ll> w(N);
vector <ll> v;
ll dfs(ll e, ll p){
    ll a=0;
    for(auto x : vec[e]){
        if(x[0]==p) continue;
        a+=dfs(x[0],e);
        w[x[0]]=x[1];
        v.push_back(x[0]);
    }
    if(!a) a=1;
    sl[e]=a;
    return sl[e];
}

int main(){
    IOS;
    make(ll,t);
    while(t--){
        make2(ll,n,k);
        fr(i,n) vec[i].clear();
        fr(i,n) sl[i]=0;
        fr(i,n) w[i]=0;
        v.clear();
        fr(i,n-1){
            make2(ll,x,y); make(ll,a);
            vec[--x].push_back({--y,a});
            vec[y].push_back({x,a});
        }
        dfs(0,-1);
        set <array <ll,2>, greater <array <ll,2> > > s;
        ll sum=0;
        for(auto i : v){
            ll a=w[i]*sl[i]-(w[i]/2)*sl[i];
            s.insert({a,i});
            sum+=w[i]*sl[i];
        } ll ans=0;
        while(sum>k){
            auto a=*s.begin();
            sum-=a[0];
            s.erase(s.begin());
            w[a[1]]/=2;
            ll c=w[a[1]]*sl[a[1]]-(w[a[1]]/2)*sl[a[1]];
            a[0]=c;
            s.insert(a);
            ans++;
        }
        cout<<ans<<endl;

    }

// 1 5 10 1 2 20 1 3 20 2 4 10 2 5 10
    return 0;
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

//
using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}
ll N=1e5+5;
vector <ll> st(N);
struct cmp {
	bool operator() (const array <ll,2> &a, const array <ll,2> &b) const {
		return a[0]-((a[0]/st[a[1]])/2)*st[a[1]]>b[0]-((b[0]/st[b[1]])/2)*st[b[1]];
	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};

multiset < array<ll,2> , cmp > s;

vector <vector <array <ll,2> > >vec(N);

ll dfs(ll e, ll p){
    bool f=1;
    ll a=0;
    for(auto x : vec[e]){
        if(x[0]==p) continue;
        f=0;
        a+=dfs(x[0],e);
        s.insert({st[x[0]]*x[1],x[0]});
    }
    if(f) st[e]=1;
    else st[e]=a;
    return st[e];
}

int main(){
    IOS;
    make(ll,t);
    while(t--){
        s.clear();
        make2(ll,n,q);
        fr(i,n) vec[i].clear();
        fr(i,n) st[i]=0;
        fr(i,n-1){
            make2(ll,x,y); make(ll,a);
            vec[--x].push_back({--y,a});
            vec[y].push_back({x,a});
        }
        dfs(0,-1);
        ll ss=0;
     //   cout<<s.size()<<"dd"<<endl;
        for(auto x : s){
            ss+=x[0];
           // cout<<x<<endl;
        }
        ll ans=0;
       // fr(i,n) cout<<st[i]<<" ";
      //  cout<<endl;

        while(ss>q){
            if(!s.size()) break;
            auto p=*s.begin();
            ss-=p[0];
            p[0]/=st[p[1]]; p[0]/=2; p[0]*=st[p[1]];
            ss+=p[0];
           // cout<<ss<<"a"<<endl;
            s.erase(s.begin());
            s.insert(p);
            ans++;
        }
        cout<<ans<<endl;

    }

// 1 5 10 1 2 20 1 3 20 2 4 10 2 5 10
    return 0;
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e5+5;
multiset <ll, greater <ll> > s;
vector <ll> st(N);
vector <vector <array <ll,2> > >vec(N);

ll dfs(ll e, ll p){
    bool f=1;
    ll a=0;
    for(auto x : vec[e]){
        if(x[0]==p) continue;
        f=0;
        a+=dfs(x[0],e);
        s.insert(st[x[0]]*x[1]);
    }
    if(f) st[e]=1;
    else st[e]=a;
    return st[e];

    return a;
}

int main(){
    IOS;
    make(ll,t);
    while(t--){
        s.clear();
        make2(ll,n,q);
        fr(i,n) vec[i].clear();
        fr(i,n) st[i]=0;
        fr(i,n-1){
            make2(ll,x,y); make(ll,a);
            vec[--x].push_back({--y,a});
            vec[y].push_back({x,a});
        }
        dfs(0,-1);
        ll ss=0;
     //   cout<<s.size()<<"dd"<<endl;
        for(auto x : s){
            ss+=x;
          //  cout<<x<<endl;
        }
        ll ans=0;
       // fr(i,n) cout<<st[i]<<" ";
      //  cout<<endl;
        while(ss>q){
            ll p=*s.begin();
            ss-=p; p/=2; ss+=p;
           // cout<<ss<<"a"<<endl;
            s.erase(s.begin());
            s.insert(p);
            ans++;
        }
        cout<<ans<<endl;

    }

    return 0;
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e5+5;
multiset < array<ll,2> , greater <array <ll,2> > > s;
vector <ll> st(N);
vector <vector <array <ll,2> > >vec(N);

ll dfs(ll e, ll p){
    bool f=1;
    ll a=0;
    for(auto x : vec[e]){
        if(x[0]==p) continue;
        f=0;
        a+=dfs(x[0],e);
        s.insert({st[x[0]]*x[1],x[0]});
    }
    if(f) st[e]=1;
    else st[e]=a;
    return st[e];
}

int main(){
    IOS;
    make(ll,t);
    while(t--){
        s.clear();
        make2(ll,n,q);
        fr(i,n) vec[i].clear();
        fr(i,n) st[i]=0;
        fr(i,n-1){
            make2(ll,x,y); make(ll,a);
            vec[--x].push_back({--y,a});
            vec[y].push_back({x,a});
        }
        dfs(0,-1);
        ll ss=0;
     //   cout<<s.size()<<"dd"<<endl;
        for(auto x : s){
            ss+=x[0];
           // cout<<x<<endl;
        }
        ll ans=0;
       // fr(i,n) cout<<st[i]<<" ";
      //  cout<<endl;
      if(ss<=q) cout<<"0 \n";
      else{
        while(ss>q){
            if(!s.size()) break;
            auto  p=*s.begin();
            ss-=p[0];
            p[0]/=st[p[1]]; p[0]/=2; p[0]*=st[p[1]];
            ss+=p[0];
           // cout<<ss<<"a"<<endl;
            s.erase(s.begin());
            s.insert(p);
            ans++;
        }
        cout<<ans<<endl;
      }

    }

// 1 5 10 1 2 20 1 3 20 2 4 10 2 5 10
    return 0;
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const array <ll,2> &a, const array <ll,2> &b) const {
		return a[0]-((a[0]/a[1])/2)*a[1]>b[0]-((b[0]/b[1])/2)*a[1];
	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e5+5;
multiset < array<ll,2> , cmp > s;
vector <ll> st(N);
vector <vector <array <ll,2> > >vec(N);

ll dfs(ll e, ll p){
    bool f=1;
    ll a=0;
    for(auto x : vec[e]){
        if(x[0]==p) continue;
        f=0;
        a+=dfs(x[0],e);
        s.insert({st[x[0]]*x[1],st[x[0]]});
    }
    if(f) st[e]=1;
    else st[e]=a;
    return st[e];
}

int main(){
    IOS;
    make(ll,t);
    while(t--){
        s.clear();
        make2(ll,n,q);
        fr(i,n) vec[i].clear();
        fr(i,n) st[i]=0;
        fr(i,n-1){
            make2(ll,x,y); make(ll,a);
            vec[--x].push_back({--y,a});
            vec[y].push_back({x,a});
        }
        dfs(0,-1);
        ll ss=0;
     //   cout<<s.size()<<"dd"<<endl;
        for(auto x : s){
            ss+=x[0];
           // cout<<x<<endl;
        }
        ll ans=0;
       // fr(i,n) cout<<st[i]<<" ";
      //  cout<<endl;

        while(ss>q){
            if(!s.size()) break;
            auto p=*s.begin();
            ss-=p[0];
            p[0]/=p[1]; p[0]/=2; p[0]*=p[1];
            ss+=p[0];
           // cout<<ss<<"a"<<endl;
            s.erase(s.begin());
            s.insert(p);
            ans++;
        }
        cout<<ans<<endl;

    }

// 1 5 10 1 2 20 1 3 20 2 4 10 2 5 10
    return 0;
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}
ll N=1e5+5;
vector <ll> st(N);
struct cmp {
	bool operator() (const array <ll,2> &a, const array <ll,2> &b) const {
		return a[0]-((a[0]/st[a[1]])/2)*st[a[1]]>b[0]-((b[0]/st[b[1]])/2)*st[b[1]];
	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};

set < array<ll,2> , cmp > s;

vector <vector <array <ll,2> > >vec(N);

ll dfs(ll e, ll p){
    bool f=1;
    ll a=0;
    for(auto x : vec[e]){
        if(x[0]==p) continue;
        f=0;
        a+=dfs(x[0],e);
        s.insert({st[x[0]]*x[1],x[0]});
    }
    if(f) st[e]=1;
    else st[e]=a;
    return st[e];
}

int main(){
    IOS;
    make(ll,t);
    while(t--){
        s.clear();
        make2(ll,n,q);
        fr(i,n) vec[i].clear();
        fr(i,n) st[i]=0;
        fr(i,n-1){
            make2(ll,x,y); make(ll,a);
            vec[--x].push_back({--y,a});
            vec[y].push_back({x,a});
        }
        dfs(0,-1);
        ll ss=0;
     //   cout<<s.size()<<"dd"<<endl;
        for(auto x : s){
            ss+=x[0];
           // cout<<x<<endl;
        }
        ll ans=0;
       // fr(i,n) cout<<st[i]<<" ";
      //  cout<<endl;

        while(ss>q){
            if(!s.size()) break;
            auto p=*s.begin();
            ss-=p[0];
            p[0]/=st[p[1]]; p[0]/=2; p[0]*=st[p[1]];
            ss+=p[0];
           // cout<<ss<<"a"<<endl;
            s.erase(s.begin());
            s.insert(p);
            ans++;
        }
        cout<<ans<<endl;

    }

// 1 5 10 1 2 20 1 3 20 2 4 10 2 5 10
    return 0;
}


#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};

struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}

bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e5+5;
multiset <ll, greater <ll> > s;
vector <ll> st(N);
vector <vector <array <ll,2> > >vec(N);

ll dfs(ll e, ll p){
    bool f=1;
    ll a=0;
    for(auto x : vec[e]){
        if(x[0]==p) continue;
        f=0;
        a+=dfs(x[0],e);
        s.insert(st[x[0]]*x[1]);
    }
    if(f) st[e]=1;
    else st[e]=a;
    return st[e];
}

int main(){
    IOS;
    make(ll,t);
    while(t--){
        s.clear();
        make2(ll,n,q);
        fr(i,n) vec[i].clear();
        fr(i,n) st[i]=0;
        fr(i,n-1){
            make2(ll,x,y); make(ll,a);
            vec[--x].push_back({--y,a});
            vec[y].push_back({x,a});
        }
        dfs(0,-1);
        ll ss=0;
     //   cout<<s.size()<<"dd"<<endl;
        for(auto x : s){
            ss+=x;
           // cout<<x<<endl;
        }
        ll ans=0;
       // fr(i,n) cout<<st[i]<<" ";
      //  cout<<endl;
      if(ss<=q) cout<<"0 \n";
      else{
        while(ss>q){
            ll p=*s.begin();
            ss-=p; p/=2; ss+=p;
           // cout<<ss<<"a"<<endl;
            s.erase(s.begin());
            s.insert(p);
            ans++;
        }
        cout<<ans<<endl;
      }

    }

// 1 5 10 1 2 20 1 3 20 2 4 10 2 5 10
    return 0;
}


#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

#define INF 2E9
#define INF64 4E18

using namespace std;

template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
  pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
  pr("{",x.first,", ",x.second,"}");
}
template<class T> void prContain(const T& x) {
  pr("{");bool fst = 1; for(auto &a: x) pr(!fst?", ":"",a), fst = 0;pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

void ps() { pr("\n"); }
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
  pr(first," "); ps(rest...); // print w/ spaces
}

template<typename T> int remin(T& a,const T& b){if(b<a){a=b;return true;}return false;}
template<typename T> int remax(T& a,const T& b){if(b>a){a=b;return true;}return false;}

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int n;
ll S;
vector<vector<ii>> G;
int leaves[100005];
set<ll> st;
ll total;

int dfs(int u, int p = -1) {
  int total = 0;
  for (ii v: G[u]) if (v.first != p) {
    total += dfs(v.first, u);
  }
  return leaves[u] = max(1, total);
}

void dfs2(int u, int p = -1) {
  for (ii v: G[u]) if (v.first != p) {
    st.insert(leaves[v.first] * v.second);
    total += leaves[v.first] * v.second;
    dfs2(v.first, u);
  }
}

void solve() {
  scanf("%d%lld", &n, &S);
  st.clear();
  total = 0;
  for (int i = 0; i < n; ++i) leaves[i] = 0;
  G.assign(n, vector<ii>(0));
  for (int i = 0; i < n-1; ++i) {
    int u, v, w; scanf("%d%d%d", &u, &v, &w);
    --u, --v;
    G[u].push_back(ii(v, w));
    G[v].push_back(ii(u, w));
  }
  dfs(0);
  dfs2(0);
  int ans = 0;
  while (total > S) {
    auto ptr = --st.end();
    ll k = (*ptr)/2;
    total -= (*ptr) - k;
    st.erase(ptr);
    st.insert(k);
    ++ans;
  }
  printf("%d\n", ans);
}

int main(int argc, const char **argv) {
  int TT; scanf("%d", &TT);
  for (int tt = 1; tt <= TT; ++tt) {
    solve();
  }
  return 0;
}


#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

#define INF 2E9
#define INF64 4E18

using namespace std;

template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
  pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
  pr("{",x.first,", ",x.second,"}");
}
template<class T> void prContain(const T& x) {
  pr("{");bool fst = 1; for(auto &a: x) pr(!fst?", ":"",a), fst = 0;pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

void ps() { pr("\n"); }
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
  pr(first," "); ps(rest...); // print w/ spaces
}

template<typename T> int remin(T& a,const T& b){if(b<a){a=b;return true;}return false;}
template<typename T> int remax(T& a,const T& b){if(b>a){a=b;return true;}return false;}

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef tuple<ll, ll, ll> iii;
typedef tuple<ll, ll, ll, ll> iiii;
typedef vector<ii> vii;

int n;
ll S;
vector<vector<ii>> G;
ll leaves[100005];
ll total;

inline ll get_diff(ll a, ll b) {
  return a * (b - (b/2));
}

ll dfs(int u, int p = -1) {
  ll total = 0;
  for (auto [v, e]: G[u]) if (v != p) {
    total += dfs(v, u);
    leaves[e] = dfs(v, u);
  }
  return max(1LL, total);
}

void solve() {
  scanf("%d%lld", &n, &S);
  priority_queue<iii> q;
  vi W(n), C(n);
  total = 0;
  for (int i = 0; i < n-1; ++i) leaves[i] = 0;
  G.assign(n, vii(0));
  for (int e = 0; e < n-1; ++e) {
    int u, v, w; scanf("%d%d%d", &u, &v, &w);
    W[e] = w;
    --u, --v;
    G[u].push_back({v, e});
    G[v].push_back({u, e});
  }
  dfs(0);

  for (int e = 0; e < n-1; ++e) {
    q.push({ get_diff(leaves[e], W[e]), leaves[e], W[e]});
    total += 1LL * leaves[e] * W[e];
  }

  int ans = 0;
  while (total > S) {
    auto [c, a, b] = q.top();
    total -= get_diff(a, b);
    b /= 2;
    q.pop();
    q.push({ get_diff(a, b), a, b });
    ++ans;
  }
  printf("%d\n", ans);
}

int main(int argc, const char **argv) {
  int TT; scanf("%d", &TT);
  for (int tt = 1; tt <= TT; ++tt) {
    solve();
  }
  return 0;
}


#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

#define INF 2E9
#define INF64 4E18

using namespace std;

template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
  pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
  pr("{",x.first,", ",x.second,"}");
}
template<class T> void prContain(const T& x) {
  pr("{");bool fst = 1; for(auto &a: x) pr(!fst?", ":"",a), fst = 0;pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

void ps() { pr("\n"); }
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
  pr(first," "); ps(rest...); // print w/ spaces
}

template<typename T> int remin(T& a,const T& b){if(b<a){a=b;return true;}return false;}
template<typename T> int remax(T& a,const T& b){if(b>a){a=b;return true;}return false;}

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ii> vii;

int n;
ll S;
vector<vector<ii>> G;
int leaves[100005];
ll total;

int dfs(int u, int p = -1) {
  int total = 0;
  for (ii v: G[u]) if (v.first != p) {
    total += dfs(v.first, u);
  }
  return leaves[u] = max(1, total);
}

void dfs2(priority_queue<iii> &q, int u, int p = -1) {
  for (ii v: G[u]) if (v.first != p) {
    q.push(iii(1LL * leaves[v.first] * ((v.second + 1LL)/2), leaves[v.first], v.second));
    total += 1LL * leaves[v.first] * v.second;
    dfs2(q, v.first, u);
  }
}

void solve() {
  scanf("%d%lld", &n, &S);
  priority_queue<iii> q;
  total = 0;
  for (int i = 0; i < n; ++i) leaves[i] = 0;
  G.assign(n, vector<ii>(0));
  for (int i = 0; i < n-1; ++i) {
    int u, v, w; scanf("%d%d%d", &u, &v, &w);
    --u, --v;
    G[u].push_back(ii(v, w));
    G[v].push_back(ii(u, w));
  }
  dfs(0);
  dfs2(q, 0);
  int ans = 0;
  while (total > S) {
    auto [c, a, b] = q.top();
    total -= a * b - a * (b/2);
    b /= 2;
    q.pop();
    q.push(iii(a*((b+1LL)/2), a, b));
    ++ans;
  }
  printf("%d\n", ans);
}

int main(int argc, const char **argv) {
  int TT; scanf("%d", &TT);
  for (int tt = 1; tt <= TT; ++tt) {
    solve();
  }
  return 0;
}


#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

#define INF 2E9
#define INF64 4E18

using namespace std;

template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
  pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
  pr("{",x.first,", ",x.second,"}");
}
template<class T> void prContain(const T& x) {
  pr("{");bool fst = 1; for(auto &a: x) pr(!fst?", ":"",a), fst = 0;pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

void ps() { pr("\n"); }
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
  pr(first," "); ps(rest...); // print w/ spaces
}

template<typename T> int remin(T& a,const T& b){if(b<a){a=b;return true;}return false;}
template<typename T> int remax(T& a,const T& b){if(b>a){a=b;return true;}return false;}

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int n;
ll S;
vector<vector<ii>> G;
int leaves[100005];
set<ll> st;
ll total;

int dfs(int u, int p = -1) {
  int total = 0;
  for (ii v: G[u]) if (v.first != p) {
    total += dfs(v.first, u);
  }
  return leaves[u] = max(1, total);
}

void dfs2(priority_queue<int> &q, int u, int p = -1) {
  for (ii v: G[u]) if (v.first != p) {
    st.insert(leaves[v.first] * v.second);
    q.push(leaves[v.first] * v.second);
    total += leaves[v.first] * v.second;
    dfs2(q, v.first, u);
  }
}

void solve() {
  scanf("%d%lld", &n, &S);
  st.clear();
  priority_queue<int> q;
  total = 0;
  for (int i = 0; i < n; ++i) leaves[i] = 0;
  G.assign(n, vector<ii>(0));
  for (int i = 0; i < n-1; ++i) {
    int u, v, w; scanf("%d%d%d", &u, &v, &w);
    --u, --v;
    G[u].push_back(ii(v, w));
    G[v].push_back(ii(u, w));
  }
  dfs(0);
  dfs2(q, 0);
  int ans = 0;
  while (total > S) {
    int v = q.top();
    q.pop();
    ll k = v/2;
    total -= v - k;
    q.push(k);
    ++ans;
  }
  printf("%d\n", ans);
}

int main(int argc, const char **argv) {
  int TT; scanf("%d", &TT);
  for (int tt = 1; tt <= TT; ++tt) {
    solve();
  }
  return 0;
}


#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

#define INF 2E9
#define INF64 4E18

using namespace std;

template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
  pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
  pr("{",x.first,", ",x.second,"}");
}
template<class T> void prContain(const T& x) {
  pr("{");bool fst = 1; for(auto &a: x) pr(!fst?", ":"",a), fst = 0;pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

void ps() { pr("\n"); }
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
  pr(first," "); ps(rest...); // print w/ spaces
}

template<typename T> int remin(T& a,const T& b){if(b<a){a=b;return true;}return false;}
template<typename T> int remax(T& a,const T& b){if(b>a){a=b;return true;}return false;}

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef tuple<ll, ll, ll> iii;
typedef tuple<ll, ll, ll, ll> iiii;
typedef vector<ii> vii;

int n;
ll S;
vector<vector<ii>> G;
ll leaves[100005];
ll total;

inline ll get_diff(ll a, ll b) {
  return a * b - a * (b/2);
}

ll dfs(int u, int p = -1) {
  ll total = 0;
  for (auto [v, e]: G[u]) if (v != p) {
    total += dfs(v, u);
    leaves[e] = dfs(v, u);
  }
  return max(1LL, total);
}

void solve() {
  scanf("%d%lld", &n, &S);
  priority_queue<iii> q;
  vi W(n), C(n);
  total = 0;
  for (int i = 0; i < n-1; ++i) leaves[i] = 0;
  G.assign(n, vii(0));
  for (int e = 0; e < n-1; ++e) {
    int u, v, w; scanf("%d%d%d", &u, &v, &w);
    W[e] = w;
    --u, --v;
    G[u].push_back({v, e});
    G[v].push_back({u, e});
  }
  dfs(0);

  for (int e = 0; e < n-1; ++e) {
    q.push({ get_diff(leaves[e], W[e]), leaves[e], W[e]});
    total += leaves[e] * W[e];
  }

  int ans = 0;
  while (total > S) {
    auto [c, a, b] = q.top();
    if (get_diff(a, b) == 0) exit(1);
    total -= get_diff(a, b);
    b /= 2;
    q.pop();
    q.push({ get_diff(a, b), a, b });
    ++ans;
  }
  printf("%d\n", ans);
}

int main(int argc, const char **argv) {
  int TT; scanf("%d", &TT);
  for (int tt = 1; tt <= TT; ++tt) {
    solve();
  }
  return 0;
}


#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

#define INF 2E9
#define INF64 4E18

using namespace std;

template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
  pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
  pr("{",x.first,", ",x.second,"}");
}
template<class T> void prContain(const T& x) {
  pr("{");bool fst = 1; for(auto &a: x) pr(!fst?", ":"",a), fst = 0;pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

void ps() { pr("\n"); }
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
  pr(first," "); ps(rest...); // print w/ spaces
}

template<typename T> int remin(T& a,const T& b){if(b<a){a=b;return true;}return false;}
template<typename T> int remax(T& a,const T& b){if(b>a){a=b;return true;}return false;}

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef tuple<ll, ll, ll> iii;
typedef tuple<ll, ll, ll, ll> iiii;
typedef vector<ii> vii;

int n;
ll S;
vector<vector<ii>> G;
ll leaves[100005];
ll total;

inline ll get_diff(ll a, ll b) {
  return a * b - a * (b/2);
}

ll dfs(int u, int p = -1) {
  ll total = 0;
  for (auto [v, e]: G[u]) if (v != p) {
    total += dfs(v, u);
    leaves[e] = dfs(v, u);
  }
  return max(1LL, total);
}

void solve() {
  scanf("%d%lld", &n, &S);
  priority_queue<iii> q;
  vi W(n), C(n);
  total = 0;
  for (int i = 0; i < n-1; ++i) leaves[i] = 0;
  G.assign(n, vii(0));
  for (int e = 0; e < n-1; ++e) {
    int u, v, w; scanf("%d%d%d", &u, &v, &w);
    W[e] = w;
    --u, --v;
    G[u].push_back({v, e});
    G[v].push_back({u, e});
  }
  dfs(0);

  for (int e = 0; e < n-1; ++e) {
    q.push({ get_diff(leaves[e], W[e]), leaves[e], W[e]});
    total += leaves[e] * W[e];
  }

  int ans = 0;
  while (total > S) {
    auto [c, a, b] = q.top();
    if (get_diff(a, b) <= 0) exit(1);
    total -= get_diff(a, b);
    b /= 2;
    q.pop();
    q.push({ get_diff(a, b), a, b });
    ++ans;
  }
  printf("%d\n", ans);
}

int main(int argc, const char **argv) {
  int TT; scanf("%d", &TT);
  for (int tt = 1; tt <= TT; ++tt) {
    solve();
  }
  return 0;
}


#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

#define INF 2E9
#define INF64 4E18

using namespace std;

template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
  pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
  pr("{",x.first,", ",x.second,"}");
}
template<class T> void prContain(const T& x) {
  pr("{");bool fst = 1; for(auto &a: x) pr(!fst?", ":"",a), fst = 0;pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

void ps() { pr("\n"); }
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
  pr(first," "); ps(rest...); // print w/ spaces
}

template<typename T> int remin(T& a,const T& b){if(b<a){a=b;return true;}return false;}
template<typename T> int remax(T& a,const T& b){if(b>a){a=b;return true;}return false;}

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef tuple<ll, ll, ll> iii;
typedef tuple<ll, ll, ll, ll> iiii;
typedef vector<ii> vii;

int n;
ll S;
vector<vector<ii>> G;
ll leaves[100005];
ll total;

inline ll get_diff(ll a, ll b) {
  return a * b - a * (b/2);
}

ll dfs(int u, int p = -1) {
  ll total = 0;
  for (auto [v, e]: G[u]) if (v != p) {
    total += dfs(v, u);
    leaves[e] = dfs(v, u);
  }
  return max(1LL, total);
}

void solve() {
  scanf("%d%lld", &n, &S);
  priority_queue<iii> q;
  vi W(n), C(n);
  total = 0;
  for (int i = 0; i < n-1; ++i) leaves[i] = 0;
  G.assign(n, vii(0));
  for (int e = 0; e < n-1; ++e) {
    int u, v, w; scanf("%d%d%d", &u, &v, &w);
    W[e] = w;
    --u, --v;
    G[u].push_back({v, e});
    G[v].push_back({u, e});
  }
  dfs(0);

  for (int e = 0; e < n-1; ++e) {
    q.push({ get_diff(leaves[e], W[e]), leaves[e], W[e]});
    total += leaves[e] * W[e];
  }

  int ans = 0;
  while (total > S) {
    auto [c, a, b] = q.top();
    total -= get_diff(a, b);
    b /= 2;
    q.pop();
    q.push({ get_diff(a, b), a, b });
    ++ans;
  }
  printf("%d\n", ans);
}

int main(int argc, const char **argv) {
  int TT; scanf("%d", &TT);
  for (int tt = 1; tt <= TT; ++tt) {
    solve();
  }
  return 0;
}


#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

#define INF 2E9
#define INF64 4E18

using namespace std;

template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
  pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
  pr("{",x.first,", ",x.second,"}");
}
template<class T> void prContain(const T& x) {
  pr("{");bool fst = 1; for(auto &a: x) pr(!fst?", ":"",a), fst = 0;pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

void ps() { pr("\n"); }
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
  pr(first," "); ps(rest...); // print w/ spaces
}

template<typename T> int remin(T& a,const T& b){if(b<a){a=b;return true;}return false;}
template<typename T> int remax(T& a,const T& b){if(b>a){a=b;return true;}return false;}

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef tuple<ll, ll, ll> iii;
typedef tuple<ll, ll, ll, ll> iiii;
typedef vector<ii> vii;

int n;
ll S;
vector<vector<ii>> G;
ll leaves[100005];
ll total;

inline ll get_diff(ll a, ll b) {
  return a * (b - (b/2));
}

ll dfs(int u, int p = -1) {
  ll total = 0;
  for (auto [v, e]: G[u]) if (v != p) {
    int r = dfs(v, u);
    total += r;
    leaves[e] = r;
  }
  return max(1LL, total);
}

void solve() {
  scanf("%d%lld", &n, &S);
  priority_queue<iii> q;
  vi W(n), C(n);
  total = 0;
  for (int i = 0; i < n-1; ++i) leaves[i] = 0;
  G.assign(n, vii(0));
  for (int e = 0; e < n-1; ++e) {
    int u, v, w; scanf("%d%d%d", &u, &v, &w);
    W[e] = w;
    --u, --v;
    G[u].push_back({v, e});
    G[v].push_back({u, e});
  }
  dfs(0);
  for (int e = 0; e < n-1; ++e) {
    q.push({ get_diff(leaves[e], W[e]), leaves[e], W[e]});
    total += 1LL * leaves[e] * W[e];
  }
  int ans = 0;
  while (total > S) {
    auto [c, a, b] = q.top();
    total -= get_diff(a, b);
    b /= 2;
    q.pop();
    q.push({ get_diff(a, b), a, b });
    ++ans;
  }
  printf("%d\n", ans);
}

int main(int argc, const char **argv) {
  int TT; scanf("%d", &TT);
  for (int tt = 1; tt <= TT; ++tt) {
    solve();
  }
  return 0;
}


#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

#define INF 2E9
#define INF64 4E18

using namespace std;

template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
  pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
  pr("{",x.first,", ",x.second,"}");
}
template<class T> void prContain(const T& x) {
  pr("{");bool fst = 1; for(auto &a: x) pr(!fst?", ":"",a), fst = 0;pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }

void ps() { pr("\n"); }
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
  pr(first," "); ps(rest...); // print w/ spaces
}

template<typename T> int remin(T& a,const T& b){if(b<a){a=b;return true;}return false;}
template<typename T> int remax(T& a,const T& b){if(b>a){a=b;return true;}return false;}

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef tuple<ll, ll, ll> iii;
typedef tuple<ll, ll, ll, ll> iiii;
typedef vector<ii> vii;

int n;
ll S;
vector<vector<ii>> G;
ll leaves[100005];
ll total;

inline ll get_diff(ll a, ll b) {
  return a * b - a * (b/2);
}

int dfs(int u, int p = -1) {
  int total = 0;
  for (auto [v, e]: G[u]) if (v != p) {
    total += dfs(v, u);
    leaves[e] = dfs(v, u);
  }
  return max(1, total);
}

void solve() {
  scanf("%d%lld", &n, &S);
  priority_queue<iii> q;
  vi W(n), C(n);
  total = 0;
  for (int i = 0; i < n-1; ++i) leaves[i] = 0;
  G.assign(n, vii(0));
  for (int e = 0; e < n-1; ++e) {
    int u, v, w; scanf("%d%d%d", &u, &v, &w);
    W[e] = w;
    --u, --v;
    G[u].push_back({v, e});
    G[v].push_back({u, e});
  }
  dfs(0);

  for (int e = 0; e < n-1; ++e) {
    q.push({get_diff(leaves[e], W[e]), leaves[e], W[e]});
    total += leaves[e] * W[e];
  }

  int ans = 0;
  while (total > S) {
    auto [c, a, b] = q.top();
    total -= get_diff(a, b);
    b /= 2;
    q.pop();
    q.push({ get_diff(a, b), a, b });
    ++ans;
  }
  printf("%d\n", ans);
}

int main(int argc, const char **argv) {
  int TT; scanf("%d", &TT);
  for (int tt = 1; tt <= TT; ++tt) {
    solve();
  }
  return 0;
}