Problem: Easy and hard versions are actually different problems, so we advise you to read both statements carefully.

You are given a weighted rooted tree, vertex 1 is the root of this tree.

A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex v is the last different from v vertex on the path from the root to the vertex v. Children of vertex v are all vertices for which v is the parent. A vertex is a leaf if it has no children. The weighted tree is such a tree that each edge of this tree has some weight.

The weight of the path is the sum of edges weights on this path. The weight of the path from the vertex to itself is 0.

You can make a sequence of zero or more moves. On each move, you select an edge and divide its weight by 2 rounding down. More formally, during one move, you choose some edge i and divide its weight by 2 rounding down (w_i := \left⌊(w_i)/(2)\right⌋).

Your task is to find the minimum number of moves required to make the sum of weights of paths from the root to each leaf at most S. In other words, if w(i, j) is the weight of the path from the vertex i to the vertex j, then you have to make ∑_{v ∈ leaves} w(root, v) ≤ S, where leaves is the list of all leaves.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.

The first line of the test case contains two integers n and S (2 ≤ n ≤ 10^5; 1 ≤ S ≤ 10^{16}) — the number of vertices in the tree and the maximum possible sum of weights you have to obtain. The next n-1 lines describe edges of the tree. The edge i is described as three integers v_i, u_i and w_i (1 ≤ v_i, u_i ≤ n; 1 ≤ w_i ≤ 10^6), where v_i and u_i are vertices the edge i connects and w_i is the weight of this edge.

It is guaranteed that the sum of n does not exceed 10^5 (∑ n ≤ 10^5).

Output

For each test case, print the answer: the minimum number of moves required to make the sum of weights of paths from the root to each leaf at most S.

Example

Input


3
3 20
2 1 8
3 1 7
5 50
1 3 100
1 5 10
2 3 123
5 4 55
2 100
1 2 409


Output


0
8
3

Solution (in JAVA):

Solution:

import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class N661 {
	static PrintWriter out;
	static Scanner sc;
	static int[][] q;
	static ArrayList<Integer>w,primes;
	static ArrayList<long[]>adj[];
	static HashSet<Integer>primesH;
	static boolean prime[];
	//static ArrayList<Integer>a;
	static HashSet<Long>h,tmp;
	static boolean[]v;
	static int[]a,b,c,d;
	static int dp[][][];
	static int A,B,n,m,k,mt[][];
	static int oo=Integer.MIN_VALUE;
	static String s,tt;
	public static void main(String[]args) throws IOException {
		sc=new Scanner(System.in);
		out=new PrintWriter(System.out);
		//A();
    	//B();
		//primes=new ArrayList<Integer>();
		//primesH=new HashSet<Integer>();
	//	sieveOfEratosthenes(50);
		//C();
		//D();
		E1();
		//minimum for subarrays of fixed length
		//F();
		out.close();
	}
	  private static void A() throws IOException {
		  int t=ni();
			a:while(t-->0) {
				n=ni();
				a=nai(n);
				Arrays.sort(a);
				for(int i=1;i<n;i++) {
					if(a[i]-a[i-1]>1) {
						ol("NO");
						continue a;
						
					}
				}
				ol("YES");
			}
	   }
		static void B() throws IOException {
			int t=ni();
			while(t-->0) {
				n=ni();
				a=nai(n);
				b=nai(n);
				int mna=Integer.MAX_VALUE;
				int mnb=Integer.MAX_VALUE;
				long ans=0l;
				for(int i=0;i<n;i++) {
					mna=Math.min(mna, a[i]);
					mnb=Math.min(mnb, b[i]);
				}
				for(int i=0;i<n;i++) {
					int diff1=a[i]-mna;
					int diff2=b[i]-mnb;
					ans+=Math.min(diff1, diff2);
					ans+=Math.abs(diff1-diff2);
				}
				ol(ans+"");
			}
		}
	  static void C() throws IOException {
		  int t=ni();
		  while(t-->0) {
			   n=ni();
			   a=nai(n);
			   ArrayList<Point>occ[]=new ArrayList[2*n+1];
			   for(int i=0;i<occ.length;i++)
				   occ[i]=new ArrayList<Point>();
			   for(int i=0;i<n;i++) {
				   for(int j=i+1;j<n;j++) {
					   occ[a[i]+a[j]].add(new Point(i,j));
				   }
			   }
			   int mx=0;
			   for(int i=0;i<occ.length;i++) {
				   boolean[]v=new boolean[n];
				   int cur=0;
				   for(Point p:occ[i]) {
					   if(!v[p.x]&&!v[p.y]) {
						   v[p.x]=v[p.y]=true;
						   cur++;
					   }
				   }
				   mx=Math.max(mx, cur);
			   }
			   ol(mx);
		  }
		  
		}



	static void D() throws IOException {
		int t=ni();
		a1:while(t-->0) {
			n=ni();
			String s=ns();
			int z=0,o=0;
			for(int i=0;i<n;i++) {
				if(s.charAt(i)=='0')z++;
				else o++;
			}
			boolean zer=s.charAt(0)=='0';
			if(zer)z--;else o--;
			int ans=0;
			int[]occ=new int[n];occ[0]=1;
			for(int i=1;i<n;i++) {
				if(s.charAt(i)=='0') {
					if(!zer) {
						occ[i]=1;
						zer=!zer;
						z--;
					}
				}else {
					if(zer) {
						occ[i]=1;
						zer=!zer;
						o--;
					}
				}
			}
			int i=1;
			while(i<n) {
				if(occ[i]==0) {
					break;
				}
				i++;
			}
			int curz=3,curo=3;
			if(i<n) {
				zer=s.charAt(i)=='0';occ[i]=2;
			}
			
			for(++i;i<n;i++) {
				if(s.charAt(i)=='0') {
					if(!zer&&occ[i]==0) {
						occ[i]=2;
						zer=!zer;
						z--;
					}
				}else{
					if(zer&&occ[i]==0) {
						occ[i]=2;
						zer=!zer;
						o--;
					}
				}
			}
			for(i=0;i<n;i++) {
				if(occ[i]!=0)continue;
				if(s.charAt(i)=='0') {
					occ[i]=curz++;
				}else {
					occ[i]=curo++;
				}
			}
			for(i=0;i<n;i++)ans=Math.max(ans, occ[i]);
			ol(ans);
			for(i=0;i<n;i++)out.print(occ[i]+" ");
			ol("");
		}
		
	}
	private static long pow(Integer x, Integer p) {
		if(p==0)return 1l;
		long sq=pow(x,p/2);
		sq*=sq;
		if(p%2==1)sq*=x*1l;
		return sq;
	}
	private static int sum(char[] ss) {
		int sum=0;
		for(int i=0;i<ss.length;i++) {
			sum+=(ss[i]-'0');
		}
		return sum;
	}
	static long gcd (long a, long b) {
	    return b==0?a:gcd (b, a % b);
	}
	static long lcm (long a, long b) {
	    return a / gcd(a, b) * b;
	}
	static PriorityQueue<long[]>pq;
	static boolean vis[];
	static long sum;
	static void E1() throws IOException {
		int t=ni();
		while(t-->0) {
			n=ni();
			long s=nl();
			adj=new ArrayList[n];
			for(int i=0;i<n;i++) {
				adj[i]=new ArrayList<long[]>();
			}
			vis=new boolean[n];
			for(int i=0;i<n-1;i++) {
				int u,v;
				long w;
				adj[u=ni()-1].add(new long[] {v=ni()-1,w=nl()});
				adj[v].add(new long[] {u,w});
			}
			pq=new PriorityQueue<long[]>((u,v)->u[2]<v[2]?-1:u[2]>v[2]?1:0);
			dfs(0l,0);
			long sum=0l;
			for(long[] x:pq) {
				sum+=(x[0]*1l*x[1]);
			}
			if(sum<=s)ol(0);
			else {
				int cnt=0;
				while(!pq.isEmpty()) {
					long []c=pq.poll();
					cnt++;
					c[1]/=2l;
					pq.add(new long[] {c[0],c[1],((c[1]/2l)-c[1])*c[0]});
					sum+=c[2];
					if(sum<=s)break;
				}
				ol(cnt);
			}
		}
	}
	private static long dfs(long prv,int i) {
			vis[i]=true;
			long leaf=0l;
			boolean ok=false;
			for(long[]e:adj[i]) {
				if(!vis[(int)e[0]]) {
					long cur=dfs(e[1],(int)e[0]);
					leaf+=cur;
					ok=true;
				}
			}
			if(!ok)leaf++;
			pq.add(new long[] {leaf,prv,((prv/2l)-prv)*leaf});
			return leaf;
	}
	static final Random random=new Random();
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	static void F() throws IOException{
		int t=1;
		while(t-->0) {
			
		}
		
	}

	private static boolean suff(int days) {
		int[]nd=new int[n];
		for(int i=0;i<n;i++)nd[i]=a[i];
		int[]lst=new int[n];
		Arrays.fill(lst, -1);
		ArrayList<Integer>idx[]=new ArrayList[(int)2e5 +1];
		for(int i=0;i<idx.length;i++)idx[i]=new ArrayList<Integer>();
		for(int []x:q) {
			if(x[0]<=days)
				lst[x[1]]=Math.max(lst[x[1]], x[0]);
		}
		for(int i=0;i<n;i++)if(lst[i]!=-1)idx[lst[i]].add(i);
		int cnt=0;
		for(int i=0;i<=days;i++) {
			cnt++;
			if(i>(int)2e5)continue;
			for(int id:idx[i]) {
				if(cnt>=nd[id]) {
					cnt-=nd[id];nd[id]=0;
				}else {
					nd[id]-=cnt;
					cnt=0;
					break;
				}
			}
		}
		int sum=0;for(int i=0;i<n;i++)sum+=nd[i];
		return sum*2<=cnt;
	}

	
	static void G() throws IOException{
		int t=1;
		while(t-->0) {

			
			
			
		}
		
	}
	private static void disp(int[] revl) {
		for(int i=0;i<revl.length;i++) {
			out.print(revl[i]+" ");
		}
		out.println();
	}

	static int ni() throws IOException {
		return sc.nextInt();
	}
	static double nd() throws IOException {
		return sc.nextDouble();
	}
	static long nl() throws IOException {
		return  sc.nextLong();
	}
	static String ns() throws IOException {
		return sc.next();
	}
	static int[] nai(int n) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();
		return a;
	}
	static long[] nal(int n) throws IOException {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextLong();
		return a;
	}
	static int[][] nmi(int n,int m) throws IOException{
		int[][]a=new int[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				a[i][j]=sc.nextInt();
			}
		}
		return a;
	}

	static long[][] nml(int n,int m) throws IOException{
		long[][]a=new long[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				a[i][j]=sc.nextLong();
			}
		}
		return a;
	}
	static void o(String x) {
		out.print(x);
	}
	static void ol(String x) {
		out.println(x);
	}
	static void ol(int x) {
		out.println(x);
	}
	static void disp1(int []a) {
		for(int i=0;i<a.length;i++) {
			out.print(a[i]+" ");
		}
		out.println();
	}

	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException 
		{
			while (st == null || !st.hasMoreTokens()) 
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public boolean hasNext() {return st.hasMoreTokens();}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		
		public double nextDouble() throws IOException {return Double.parseDouble(next());}
		
		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}
			
		public boolean ready() throws IOException {return br.ready(); }
		

	}
}