You are given $n$ rectangles, each of height $1$. Each rectangle's width is a power of $2$ (i. e. it can be represented as $2^x$ for some non-negative integer $x$).

You are also given a two-dimensional box of width $W$. Note that $W$ may or may not be a power of $2$. Moreover, $W$ is at least as large as the width of the largest rectangle.

You have to find the smallest height of this box, such that it is able to fit all the given rectangles. It is allowed to have some empty space left in this box after fitting all the rectangles.

You cannot rotate the given rectangles to make them fit into the box. Moreover, any two distinct rectangles must not overlap, i. e., any two distinct rectangles must have zero intersection area.

See notes for visual explanation of sample input.


-----Input-----

The first line of input contains one integer $t$ ($1 \le t \le 5 \cdot 10^3$) — the number of test cases. Each test case consists of two lines.

For each test case:

the first line contains two integers $n$ ($1 \le n \le 10^5$) and $W$ ($1 \le W \le 10^9$);

the second line contains $n$ integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^6$), where $w_i$ is the width of the $i$-th rectangle. Each $w_i$ is a power of $2$;

additionally, $\max\limits_{i=1}^{n} w_i \le W$.

The sum of $n$ over all test cases does not exceed $10^5$.


-----Output-----

Output $t$ integers. The $i$-th integer should be equal to the answer to the $i$-th test case — the smallest height of the box.


-----Examples-----

Input
2
5 16
1 2 8 4 8
6 10
2 8 8 2 2 8
Output
2
3


-----Note-----

For the first test case in the sample input, the following figure shows one way to fit the given five rectangles into the 2D box with minimum height:

In the figure above, the number inside each rectangle is its width. The width of the 2D box is $16$ (indicated with arrow below). The minimum height required for the 2D box in this case is $2$ (indicated on the left).

In the second test case, you can have a minimum height of three by keeping two blocks (one each of widths eight and two) on each of the three levels.

Difficulty: EASY

Solutions:
from collections import defaultdict
import heapq
T = int(input())
for _ in range(T):
	(n, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort(reverse=True)
	B = [0]
	a = heapq.heapify(B)
	ans = 0
	for i in range(n):
		v = heapq.heappop(B)
		v = -1 * v
		if v >= A[i]:
			v = v - A[i]
		else:
			ans += 1
			heapq.heappush(B, -1 * (K - A[i]))
		heapq.heappush(B, -1 * v)
	print(ans)


from sys import stdin
import math

class PriorityQueueBase:

	class _Item:
		__slots__ = ('_key', '_value')

		def __init__(self, k, v):
			self._key = k
			self._value = v

		def __lt__(self, other):
			return self._key < other._key

	def is_empty(self):
		return len(self) == 0

def queue_time(customers, n):
	for i in range(1, len(customers)):
		i = i % n
		while i % n < n and customers[i % n] > customers[(i + 1) % n]:
			i += 1
			customers[i % n] = customers[i % n] + customers[i]
			customers[i] = 0
	return customers

def phi(n):
	result = n
	for i in range(2, int(pow(n, 0.5)) + 1):
		while n % i == 0:
			n /= i
			result -= result / i
	if n > 1:
		result -= result / n
	return result
input = stdin.buffer.readline
for _ in range(int(input())):
	(n, W) = map(int, input().split())
	a = list(map(int, input().split()))
	l = [0] * 20
	for i in a:
		l[int(math.log2(i))] += 1
	c = 0
	while sum(l) != 0:
		c += 1
		res = W
		for i in range(19, -1, -1):
			while l[i] != 0 and res >= 1 << i:
				res -= 1 << i
				l[i] -= 1
	print(c)


import math
T = int(input())

def process(tab, nb_piece, width):
	tab = sorted(tab)
	data = [0] * (int(math.log(tab[-1], 2)) + 1)
	power = 1
	index = 0
	for elem in tab:
		while elem > power:
			power *= 2
			index += 1
		if elem == power:
			data[index] += 1
	stage = 1
	trous = width
	while nb_piece > 0:
		for index in range(len(data) - 1, -1, -1):
			elem = 2 ** index
			while data[index] > 0 and elem <= trous:
				data[index] -= 1
				trous -= elem
				nb_piece -= 1
		stage += 1
		trous = width
	if trous == width:
		stage -= 1
	return stage
for _ in range(T):
	data = input().split()
	(n, width) = (int(data[0]), int(data[1]))
	data = input().split()
	tab = [int(elem) for elem in data]
	res = process(tab, n, width)
	print(res)


a = int(input())
from heapq import *
for i in range(a):
	(n, w) = map(int, input().split())
	z = list(map(int, input().split()))
	z.sort(reverse=True)
	space = w
	rows = 1
	ans = []
	for i in range(len(z)):
		if space < z[i]:
			if len(ans) > 0:
				if abs(ans[0]) >= z[i]:
					t = abs(heappop(ans))
					t -= z[i]
					heappush(ans, -t)
					continue
			rows += 1
			heappush(ans, -space)
			space = w
		space -= z[i]
	print(rows)


import sys
from sys import stdout
import bisect as bi
import math
from collections import defaultdict as dd
from types import GeneratorType
from collections import deque
from heapq import heapify, heappush, heappop
from itertools import permutations
import random
input = sys.stdin.readline
mo = 10 ** 9 + 7
MOD = 998244353

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input().strip()

def inin():
	return int(input())
for _ in range(inin()):
	(n, w) = cin()
	l = ain()
	le = 0
	ri = n - 1
	ans = 0
	d = dd(int)
	for i in l:
		d[i] += 1
	po = sorted(list(d.keys()))
	re = sum(l)
	while re:
		rem = w
		fla = 0
		for i in po[::-1]:
			if d[i] and i <= rem:
				fla = 1
				mul = rem // i
				pos = min(d[i], mul)
				rem -= i * pos
				d[i] -= pos
		ans += 1
		re -= w - rem
	print(ans)

def msb(n):
	n |= n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	n |= n >> 32
	n |= n >> 64
	return n - (n >> 1)

def pref(a, n, f):
	pre = [0] * n
	if f == 0:
		pre[0] = a[0]
		for i in range(1, n):
			pre[i] = a[i] + pre[i - 1]
	else:
		pre[-1] = a[-1]
		for i in range(n - 2, -1, -1):
			pre[i] = pre[i + 1] + a[i]
	return pre

def kadane(A):
	maxSoFar = maxEndingHere = start = end = beg = 0
	for i in range(len(A)):
		maxEndingHere = maxEndingHere + A[i]
		if maxEndingHere < 0:
			maxEndingHere = 0
			beg = i + 1
		if maxSoFar < maxEndingHere:
			maxSoFar = maxEndingHere
			start = beg
			end = i
	return (maxSoFar, start, end)

def modFact(n, p):
	if n < 0:
		return 0
	if n >= p:
		return 0
	result = 1
	for i in range(1, n + 1):
		result = result * i % p
	return result

def ncr(n, r, p):
	if n < r or n < 0:
		return 0
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
sys.setrecursionlimit(111111)
INF = 999999999999999999999999

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	z = [1]
	for i in range(35):
		z.append(t * 2)
		t *= 2
	z = sorted(z)[::-1]
	tc = ri()
	for _ in range(tc):
		(n, w) = ria()
		a = ria()
		d = Counter(a)
		h = 1
		left = w
		while len(d):
			flag = 1
			rem = []
			for i in z:
				if i in d:
					while i <= left:
						left -= i
						d[i] -= 1
						if d[i] == 0:
							rem.append(i)
							break
						flag = 0
			for i in rem:
				del d[i]
			if flag and len(d):
				h += 1
				left = w
		wi(h)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import heapq
for _ in range(int(input())):
	(n, width) = map(int, input().split())
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	autosortedlist = [-width]
	heapq.heapify(autosortedlist)
	for i in w:
		if -autosortedlist[0] < i:
			heapq.heappush(autosortedlist, -width)
		temp = -autosortedlist[0]
		temp -= i
		heapq.heappushpop(autosortedlist, -temp)
	print(len(autosortedlist))


from math import log
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	a = list(map(int, input().split()))
	h = 0
	required = [0] * int(log(max(a), 2) + 1)
	for i in a:
		required[int(log(i, 2))] += 1
	b = bin(w)[2:][::-1]
	have = [0] * len(b)
	for i in range(len(b)):
		if b[i] == '1':
			have[i] = 1
	havec = have.copy()
	havelen = len(have)
	for i in range(len(required) - 1, -1, -1):
		if required[i] <= have[i]:
			have[i] -= required[i]
			required[i] = 0
		else:
			required[i] -= have[i]
			have[i] = 0
			while required[i] != 0:
				check = 0
				for j in range(i, havelen):
					if have[j] >= 1:
						have[j] -= 1
						required[i] -= 1
						for k in range(i, j):
							have[k] += 1
						check = 1
						break
				if check == 0:
					h += 1
					for k in range(havelen):
						have[k] = have[k] + havec[k]
	print(h + 1)


t = int(input())
for _ in range(t):
	(n, w) = map(int, input().split())
	lista = list(map(int, input().split()))
	lista.sort(reverse=True)
	d = {}
	for i in lista:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	h = 0
	while n > 0:
		w1 = w
		for i in d:
			while d[i] > 0 and i <= w1:
				w1 -= i
				d[i] -= 1
				n -= 1
		h += 1
	print(h)


from heapq import heappop, heappush
T = int(input())
for _ in range(T):
	(N, W) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort(reverse=True)
	lst = [0]
	idx = 0
	for a in A:
		flag = False
		v = heappop(lst)
		if v + a <= W:
			heappush(lst, v + a)
		else:
			heappush(lst, v)
			heappush(lst, a)
	print(len(lst))


t = int(input())
for _ in range(t):
	(n, y) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	ans = 0
	for i in l:
		d[i] = d.get(i, 0) + 1
	while d:
		w = y
		for j in reversed(sorted(d.keys())):
			x = min(w // j, d[j])
			d[j] -= x
			w -= x * j
			if d[j] == 0:
				del d[j]
			if w == 0:
				break
		ans += 1
	print(ans)


import sys
from math import floor, ceil
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def process(n, W, ws):
	ws.sort(reverse=True)
	digitsCount = {}
	for d in ws:
		if d in digitsCount:
			digitsCount[d] += 1
		else:
			digitsCount[d] = 1
	height = 1
	rectCount = len(ws)
	while rectCount > 0:
		Wt = W
		for digit in list(digitsCount.keys()):
			if digitsCount[digit] == 0:
				continue
			x = floor(Wt / digit)
			count = digitsCount[digit]
			if count >= x:
				digitsCount[digit] = count - x
				Wt = Wt - x * digit
				rectCount = rectCount - x
			else:
				digitsCount[digit] = 0
				Wt = Wt - count * digit
				rectCount = rectCount - count
			if Wt == 0:
				if rectCount > 0:
					height += 1
				break
		if Wt != 0 and rectCount > 0:
			height += 1
	return height

def main():
	t = inp()
	for case in range(t):
		(n, W) = inlt()
		ws = inlt()
		height = process(n, W, ws)
		print(height)
main()


from collections import Counter
for _ in range(int(input())):
	(n, w) = [int(i) for i in input().split()]
	m = [int(i) for i in input().split()]
	x = Counter(m)
	q = sorted(x.keys())[::-1]
	h = 0
	k = 0
	while k < n:
		y = w
		for j in q:
			while x[j] != 0 and y >= j:
				x[j] -= 1
				y -= j
				k += 1
		h += 1
	print(h)


def main():
	from sys import stdin, stdout
	from collections import Counter
	rl = stdin.readline
	wl = stdout.write
	for _ in range(int(rl())):
		(n, w) = map(int, rl().split())
		a = Counter((int(x) for x in rl().split()))
		a = dict(a.most_common())
		keys = sorted(a.keys(), reverse=True)
		h = -1
		while True:
			cur = 0
			h += 1
			for key in keys:
				while a[key] != 0 and cur + key <= w:
					cur += key
					a[key] -= 1
			if cur == 0:
				break
		wl(str(h) + '\n')
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = list(map(int, input().split()))
	d = dict()
	s.sort(reverse=True)
	for i in s:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	m1 = m
	ans = 0
	while n > 0:
		for j in d:
			while d[j] > 0 and j <= m1:
				m1 = m1 - j
				d[j] -= 1
				n -= 1
		m1 = m
		ans += 1
	print(ans)


from collections import Counter
t = int(input())
for ll in range(t):
	(n, we) = map(int, input().split())
	w = list(map(int, input().split(' ')))
	count = 0
	c = Counter(w)
	maxx = max(w)
	while n > 0:
		width = we
		flag = 0
		cur = 0
		m = maxx
		while m > 0:
			while c[m] > 0 and cur + m <= width:
				c[m] -= 1
				cur += m
				n -= 1
			m //= 2
		count += 1
	print(count)


t = int(input())
for _ in range(t):
	(n, w) = map(int, input().split())
	arr = sorted(list(map(int, input().split())), reverse=True)
	dic = {}
	answer = 0
	for i in range(n):
		if dic.get(arr[i]) == None:
			dic[arr[i]] = 1
		else:
			dic[arr[i]] += 1
	while dic != {}:
		temp = w
		answer += 1
		for key in sorted(dic.keys(), reverse=True):
			if dic[key] > 0:
				count = min(temp // key, dic[key])
				temp = temp - count * key
				dic[key] -= count
			if dic[key] == 0:
				dic.pop(key)
			if temp == 0:
				break
	print(answer)


t = int(input())
for k in range(t):
	(n, w) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		if d.get(i) == None:
			d[i] = 1
		else:
			d[i] += 1
	key = list(d.keys())
	key.sort(reverse=True)
	c = 0
	temp = w
	h = 0
	while c < len(l):
		for i in key:
			while i <= temp and d[i] > 0:
				temp -= i
				c += 1
				d[i] -= 1
		h += 1
		temp = w
	print(h)


import heapq

def sign(val):
	return -1 * val

def solve(rec, n, w):
	rec.sort(reverse=True)
	height = 1
	h = [sign(w)]
	heapq.heapify(h)
	for i in range(n):
		if len(h) == 0:
			heapq.heappush(h, sign(w))
			height += 1
		space = sign(heapq.heappop(h))
		if space > rec[i]:
			rem = space - rec[i]
			heapq.heappush(h, sign(rem))
		elif space == rec[i]:
			continue
		else:
			height += 1
			heapq.heappush(h, sign(space))
			heapq.heappush(h, sign(w - rec[i]))
	return height
t = int(input())
for _ in range(t):
	(n, w) = map(int, input().split())
	rec = list(map(int, input().split()))
	print(solve(rec, n, w))


for _ in range(int(input())):
	(n, y) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	c = 0
	for i in range(n):
		d[a[i]] = d.get(a[i], 0) + 1
	while d:
		w = y
		for i in reversed(sorted(d.keys())):
			x = min(w // i, d[i])
			d[i] -= x
			w -= x * i
			if d[i] == 0:
				del d[i]
			if w == 0:
				break
		c += 1
	print(c)


from sys import stdin, stdout
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import *
from random import *
input = stdin.readline
prin = stdout.write
from random import sample
from collections import Counter, deque
from math import sqrt, ceil, log2, gcd
mod = 10 ** 9 + 7

def f(arr, i, j, d, dist):
	if i == j:
		return
	nn = max(arr[i:j])
	for tl in range(i, j):
		if arr[tl] == nn:
			dist[tl] = d
			f(arr, i, tl, d + 1, dist)
			f(arr, tl + 1, j, d + 1, dist)

def ps(n):
	cp = 0
	lk = 0
	arr = {}
	cc = 0
	ans = 1
	while n % 2 == 0:
		n = n // 2
		lk += 1
		cc = 1
	if lk % 2 == 1:
		ans *= 2
	for ps in range(3, ceil(sqrt(n)) + 1, 2):
		lk = 0
		cc = 0
		while n % ps == 0:
			n = n // ps
			cc = 1
			lk += 1
		if lk % 2 == 1:
			ans *= ps
	if n != 1:
		ans *= n
	return ans

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def factorials(n, r):
	slr = n
	dpr = r
	qlr = 1
	qs = 1
	mod = 10 ** 9 + 7
	for ip in range(n - r + 1, n + 1):
		qlr = qlr * ip % mod
	for ij in range(1, r + 1):
		qs = qs * ij % mod
	ans = qlr * modInverse(qs) % mod
	return ans

def modInverse(b):
	qr = 10 ** 9 + 7
	return pow(b, qr - 2, qr)
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def power(arr):
	listrep = arr
	subsets = []
	for i in range(2 ** len(listrep)):
		subset = []
		for k in range(len(listrep)):
			if i & 1 << k:
				subset.append(listrep[k])
		subsets.append(subset)
	return subsets

def pda(n):
	list = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				list.append(i)
			else:
				list.append(n // i)
				list.append(i)
	return list

def dis(xa, ya, xb, yb):
	return sqrt((xa - xb) ** 2 + (ya - yb) ** 2)

def ii():
	return int(input())

def ilist():
	return [int(x) for x in input().strip().split()]

def islist():
	return list(map(str, input().split().rstrip()))

def inp():
	return input().strip()

def google(test, ans):
	return 'Case #' + str(test) + ': ' + str(ans)

def overlap(x1, y1, x2, y2):
	if x2 > y1:
		return y1 - x2
	if y1 > y2:
		return y2 - x2
	return y1 - x2
t = int(input())
for p in range(t):
	(n, w) = ilist()
	arr = ilist()
	freq = [0] * 32
	for i in range(n):
		freq[int(log2(arr[i]))] += 1
	count = 0
	while True:
		xx = w
		index = 31
		tt = 0
		while index >= 0:
			if 2 ** index <= xx and freq[index] > 0:
				xx -= 2 ** index
				freq[index] -= 1
				tt = 1
			else:
				index -= 1
		if tt == 0:
			break
		else:
			count += 1
	print(count)


def main():
	for _ in range(int(input())):
		(n, w) = map(int, input().split())
		arr = list(map(int, input().split()))
		dct = {}
		for i in arr:
			if i in dct:
				dct[i] += 1
			else:
				dct[i] = 1
		height = 0
		while sum(dct.values()):
			width = w
			for i in reversed(sorted(dct.keys())):
				while width >= i and dct[i] > 0:
					width = width - i
					dct[i] -= 1
			height += 1
		print(height)
main()


from collections import *
R = lambda : map(int, input().split())
(t,) = R()
while t:
	t -= 1
	(n, w) = R()
	c = Counter(R())
	r = 0
	while n:
		v = w
		r += 1
		x = 1 << 29
		while x:
			d = min(c[x], v // x)
			c[x] -= d
			v -= d * x
			n -= d
			x >>= 1
	print(r)


for _ in range(int(input())):
	(n, w) = map(int, input().split())
	a = list(map(int, input().split()))
	l = {}
	m = 0
	s = set()
	for i in range(n):
		if a[i] not in l:
			l[a[i]] = 1
		else:
			l[a[i]] += 1
		m = max(m, a[i])
		s.add(a[i])
	v = list(s)
	v.sort()
	v = v[::-1]
	res = 0
	i = 0
	while i < n:
		ans = 0
		for j in v:
			while l[j] > 0:
				if ans + j <= w:
					ans += j
					l[j] -= 1
					i += 1
				else:
					break
		res += 1
	print(res)


import sys
import collections
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, W) = [int(x) for x in input().split()]
		WList = [int(x) for x in input().split()]
		c = collections.Counter(WList)
		ans = 0
		while True:
			ans += 1
			haba = W
			for k in sorted(c.keys(), reverse=True):
				if haba >= k:
					x = min(haba // k, c[k])
					c[k] -= x
					haba -= x * k
			total = 0
			for (i, v) in c.items():
				total += v
			if total == 0:
				break
		print(ans)
main()


import sys
from collections import Counter
t = int(input())
for i in range(t):
	(n, w) = map(int, input().split())
	d = list(map(int, input().split()))
	kol = 0
	p = Counter(d)
	t = sorted(list(p.keys()), reverse=True)
	while len(p) > 0:
		kol += 1
		W = w
		for k in t:
			while p[k] > 0 and k <= W:
				x = k
				W -= x
				p[x] -= 1
				if p[x] == 0:
					del p[x]
	print(kol)


from collections import Counter
t = int(input())
for _ in range(t):
	(n, w) = (int(i) for i in input().split())
	rectangles = list((int(r) for r in input().split()))
	rectangles.sort(reverse=True)
	r_counter = Counter(rectangles)
	rect_and_am_pairs = list(map(list, r_counter.items()))
	res = 0
	while rect_and_am_pairs:
		layer_taken_w = 0
		rect_i = 0
		while rect_i < len(rect_and_am_pairs):
			cur_rect_am = rect_and_am_pairs[rect_i]
			max_cur_rect_per_layer = (w - layer_taken_w) // cur_rect_am[0]
			taken_rect_amount = min(max_cur_rect_per_layer, cur_rect_am[1])
			cur_rect_am[1] -= taken_rect_amount
			layer_taken_w += taken_rect_amount * cur_rect_am[0]
			rect_i += 1
			if cur_rect_am[1] == 0:
				rect_and_am_pairs.remove(cur_rect_am)
				rect_i -= 1
			if layer_taken_w == w or rect_i == len(rect_and_am_pairs) or (not rect_and_am_pairs):
				res += 1
				break
	print(res)


import math
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	count = []
	for i in range(21):
		count.append(0)
	l = list(map(int, input().split()))
	for i in range(n):
		count[int(math.log2(l[i]))] += 1
	ans = 1
	curr = w
	while True:
		i = 20
		while i >= 0:
			if count[i] > 0 and curr >= 2 ** i:
				count[i] -= 1
				curr -= 2 ** i
			else:
				i -= 1
		if sum(count) == 0:
			break
		ans += 1
		curr = w
	print(ans)


from collections import Counter

def main():
	for _ in range(int(input())):
		(n, w) = tuple(map(int, input().split()))
		a = list(map(int, input().split()))
		count = Counter(a)
		v = sorted(count.keys(), reverse=True)
		(p, h) = (w, 0)
		while n > 0:
			p = w
			for i in v:
				while count[i] and i <= p:
					p -= i
					count[i] -= 1
					n -= 1
			h += 1
		print(h)
main()


import heapq
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	mas = list(map(int, input().split()))
	mas.sort(reverse=True)
	heap = [0]
	for masw in mas:
		hp = heapq.heappop(heap)
		if masw + hp <= w:
			heapq.heappush(heap, masw + hp)
		else:
			heapq.heappush(heap, masw)
			heapq.heappush(heap, hp)
	print(len(heap))


from collections import Counter
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	arr = list(map(int, input().split()))
	count = Counter(arr)
	counts = sorted(count.keys())[::-1]
	i = 0
	height = 0
	while i < n:
		maxWidth = w
		for j in counts:
			while count[j] != 0 and maxWidth >= j:
				maxWidth -= j
				count[j] -= 1
				i += 1
		height += 1
	print(height)


import sys, math

def compute(width, sizes):
	d = {s: sizes.count(s) for s in sorted([*set(sizes)], reverse=True) if s}
	i = 0
	remaining = len(d)
	while remaining:
		i += 1
		left = width
		for (size, count) in d.items():
			while count and size <= left:
				left -= size
				d[size] -= 1
				count -= 1
				if count == 0:
					remaining -= 1
	return i
for _ in '_' * int(input()):
	(_, width) = map(int, input().split())
	sizes = [*map(int, input().split())]
	print(compute(width, sizes))


for _ in range(int(input())):
	(n, w) = map(int, input().split())
	c = {}
	for x in map(int, input().split()):
		c[x] = c.get(x, 0) + 1
	a = sorted(c)
	h = 0
	while n:
		h += 1
		t = w
		for i in range(len(a) - 1, -1, -1):
			d = min(t // a[i], c[a[i]])
			t -= a[i] * d
			c[a[i]] -= d
			n -= d
	print(h)


import bisect
t = int(input())
for _ in range(t):
	(n, W) = list(map(int, input().split()))
	widths = list(map(int, input().split()))
	widths.sort(reverse=True)
	areas_c = []
	h = 0
	for width in widths:
		pos = bisect.bisect_left(areas_c, width)
		if pos < len(areas_c):
			areas_c[pos] -= width
		else:
			areas_c.append(W - width)
			h += 1
		if areas_c[0] == 0:
			del areas_c[0]
	print(h)


import bisect
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	a = sorted(list(map(int, input().split())))[::-1]
	k = []
	c = 0
	for j in a:
		i = bisect.bisect_left(k, j)
		if i < len(k):
			k[i] = k[i] - j
		else:
			k.append(w - j)
			c += 1
	print(c)


import math
from collections import defaultdict
DEBUG = True

def log(*args, **kwargs):
	if DEBUG:
		print(*args, **kwargs)

def ri():
	return int(input())

def rl(f=int):
	return list(map(f, input().split()))

def rs():
	return input()

class Solution:

	def __init__(self):
		pass

	def run(self):
		(n, W) = rl()
		widths = rl()
		d = defaultdict(int)
		for w in widths:
			d[w] += 1
		rows = [W] * len(widths)
		for p in range(21, -1, -1):
			w = 2 ** p
			for i in range(len(rows)):
				while d[w] > 0 and rows[i] >= w:
					rows[i] -= w
					d[w] -= 1
				if d[w] == 0:
					break
		result = 0
		for r in rows:
			if r == W:
				break
			result += 1
		return result
t = int(input())
s = Solution()
for i in range(t):
	print(s.run())


for t in range(int(input())):
	(n, W) = map(int, input().split(' '))
	arr = [int(i) for i in input().split(' ')]
	d = {k: arr.count(k) for k in set(arr)}
	space_left = [W]
	for r in sorted(d.keys(), reverse=True):
		for i in range(len(space_left)):
			if space_left[i] < r:
				continue
			while d[r] != 0 and space_left[i] >= r:
				space_left[i] -= r
				d[r] -= 1
			if d[r] == 0:
				break
		else:
			while d[r] != 0:
				if d[r] - W // r >= 0:
					d[r] = d[r] - W // r
					space_left.append(W % r)
				else:
					space_left.append(W - r * d[r])
					d[r] = 0
	print(len(space_left))


for _ in range(int(input())):
	(n, w) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	for i in a:
		if d.get(i) == None:
			d[i] = 1
		else:
			d[i] += 1
	k = list(d.keys())
	k.sort(reverse=True)
	l = len(a)
	c = 0
	h = 0
	space = w
	while c < l:
		for i in k:
			while i <= space and d[i] > 0:
				space -= i
				d[i] -= 1
				c += 1
		h += 1
		space = w
	print(h)


t = int(input())
pow2 = {i: 2 ** i for i in range(31)}
log2 = {v: k for (k, v) in pow2.items()}
for _ in range(t):
	(n, w) = map(int, input().split())
	arr = [0 for _ in range(31)]
	nums = list(map(int, input().split()))
	for num in nums:
		arr[log2[num]] += 1
	pw = f'{bin(w)[2:]:0>31}'[::-1]
	ans = 0
	while True:
		changed = False
		curr2 = -1
		currleft = 0
		for i in range(30, -1, -1):
			curr2 = i
			currleft += pw[i] == '1'
			if not currleft:
				continue
			if arr[i]:
				if arr[i] >= currleft:
					arr[i] -= currleft
					currleft = 0
					changed = True
				else:
					currleft -= arr[i]
					arr[i] = 0
					changed = True
			currleft *= 2
		if not changed:
			break
		else:
			ans += 1
	print(ans)


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[0])
	return (list(a), list(b))

def number_to_list(a):
	b = []
	while a >= 1:
		c = a % 10
		a = int(a / 10)
		b.append(c)
	return list(reversed(b))

def str_list_to_int_list(a):
	a = list(map(int, a))
	return a

def make_1d_array(n, inti=0):
	a = [inti for _ in range(n)]
	return a

def make_2d_array(n, m, inti=0):
	a = [[inti for _ in range(m)] for _ in range(n)]
	return a

def make_3d_array(n, m, k, inti=0):
	a = [[[inti for _ in range(k)] for _ in range(m)] for _ in range(n)]
	return a

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
import sys
import math
import bisect
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input()))
(t,) = I()
for t1 in range(t):
	(n, w) = I()
	w1 = I()
	from collections import defaultdict
	mem1 = defaultdict(int)
	for i in range(len(w1)):
		mem1[w1[i]] += 1
	(w2, w3) = zip_sorted(list(mem1.keys()), list(mem1.values()))
	sum1 = 0
	count = 1
	while len(w2) > 0:
		idx = bisect.bisect_right(w2, w - sum1)
		if sum1 + w2[idx - 1] <= w:
			sum1 += w2[idx - 1]
			w3[idx - 1] -= 1
			if w3[idx - 1] == 0:
				w3.pop(idx - 1)
				w2.pop(idx - 1)
		else:
			count += 1
			sum1 = 0
			idx = bisect.bisect_right(w2, w - sum1)
			sum1 += w2[idx - 1]
			w3[idx - 1] -= 1
			if w3[idx - 1] == 0:
				w3.pop(idx - 1)
				w2.pop(idx - 1)
	print(count)


import collections
for _ in range(int(input())):
	(w, n) = map(int, input().split())
	c = collections.Counter(list(map(int, input().split())))
	ckey = sorted(c.keys(), reverse=True)
	h = 0
	while 1:
		nh = n
		for i in ckey:
			if nh // i > 0:
				kkk = min(c[i], nh // i)
				nh -= i * kkk
				c[i] -= kkk
		h += 1
		s = 0
		for i in ckey:
			s += c[i]
		if s == 0:
			break
	print(h)


t = int(input())
for _ in range(t):
	cnt = []
	for _ in range(20):
		cnt.append(0)
	(n, W) = map(int, input().split())
	l = list(map(int, input().split()))
	for x in l:
		for d in range(20):
			if x == 1 << d:
				cnt[d] += 1
	ans = 0
	rem = W
	while sum(cnt) > 0:
		rem = W
		ans += 1
		for i in reversed(range(20)):
			while cnt[i] > 0 and rem >= 1 << i:
				cnt[i] -= 1
				rem -= 1 << i
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter

def solve():
	(n, w) = map(int, input().split())
	L = list(map(int, input().split()))
	C = Counter(L)
	ans = 0
	while C:
		ans += 1
		left_space = w
		for i in range(30, -1, -1):
			val = 1 << i
			while val in C and left_space >= val:
				left_space -= val
				C[val] -= 1
				if C[val] == 0:
					del C[val]
	print(ans)
for _ in range(int(input())):
	solve()


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def sod(n):
	s = str(n)
	s1 = 0
	for i in s:
		s1 += int(i)
	return s1

def solve():
	for _ in range(ii()):
		(n, k) = mi()
		a = li()
		m = {}
		x = 1
		for i in range(31):
			m[x] = 0
			x *= 2
		for i in a:
			m[i] += 1
		cnt = 0
		while True:
			cnt += 1
			x = k
			for i in range(30, -1, -1):
				p = 1 << i
				x1 = min(x // p, m[p])
				x -= p * x1
				m[p] -= x1
			f = 0
			for i in m.keys():
				if m[i]:
					f = 1
					break
			if f == 0:
				break
		print(cnt)
if file:
	if path.exists('tmp/input.txt'):
		sys.stdin = open('tmp/input.txt', 'r')
		sys.stdout = open('tmp/output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
from collections import Counter as cc
(t,) = I()
for _ in range(t):
	(n, w) = I()
	l = I()
	ctr = cc(l)
	box = sorted(ctr.keys(), reverse=True)
	grd = [w]
	h = 1
	prev = 0
	for i in range(len(box)):
		i = box[i]
		(cr, cnt) = (i, ctr[i])
		for k in range(h):
			if cnt:
				pos = min(cnt, grd[k] // i)
				grd[k] -= i * min(cnt, pos)
				cnt -= pos
		while cnt:
			ar = i * min(w // i, cnt)
			grd.append(w - ar)
			h += 1
			cnt -= min(w // i, cnt)
	print(h)


from sys import stdin, stdout
input = stdin.readline

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
import bisect
t = int(input())
for _ in range(t):
	(n, w) = map(int, input().split())
	a = [int(x) for x in input().split()]
	a = SortedList(a)
	org = w
	ans = 0
	p = len(a)
	while len(a):
		if w == 0:
			w = org
			ans += 1
		index = bisect.bisect_left(a, w)
		if index < p and a[index] <= w:
			w -= a[index]
			a.remove(a[index])
			p -= 1
		elif index > 0 and a[index - 1] <= w:
			w -= a[index - 1]
			a.remove(a[index - 1])
			p -= 1
		else:
			w = org
			ans = ans + 1
	print(ans + 1)


from heapq import *
for _ in range(int(input())):
	a = []
	heapify(a)
	(n, w) = map(int, input().split())
	D = list(map(int, input().split()))
	D.sort(reverse=True)
	ans = 1
	heappush(a, -w)
	for d in D:
		t = heappop(a)
		if d > -t:
			heappush(a, t)
			heappush(a, -w + d)
			ans += 1
		else:
			heappush(a, t + d)
	print(ans)


def main(n, w, widths):
	widths.sort(reverse=True)
	d = {}
	sizes = 0
	for i in widths:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
			sizes += 1
	height = 0
	curr_space = w
	while sizes > 0:
		height += 1
		curr_space = w
		for i in d.keys():
			while d[i] > 0 and curr_space >= i:
				d[i] -= 1
				curr_space -= i
				if d[i] <= 0:
					sizes -= 1
	return height
t = int(input())
for case in range(t):
	(n, w) = [int(x) for x in input().split()]
	widths = [int(x) for x in input().split()]
	result = main(n, w, widths)
	print(result)


from functools import reduce
t = int(input())
for i in range(t):
	(n, w) = map(int, input().split())
	a = map(int, input().split())
	list_n = list(a)
	list_n.sort(reverse=True)
	dic = {}
	for i in range(len(list_n)):
		if list_n[i] in dic:
			dic[list_n[i]] += 1
		else:
			dic[list_n[i]] = 1
	cnt = 0
	length = len(list_n)
	while length:
		sum = 0
		for key in dic.keys():
			while dic[key] != 0 and w >= sum + key:
				sum += key
				dic[key] -= 1
				length -= 1
		cnt += 1
	print(cnt)


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby
for i in range(II()):
	(n, w) = LI()
	a = LI()
	fit = [w] * n
	a.sort(reverse=True)
	for i in a:
		ind = bisect_left(fit, i)
		fit[ind] -= i
	ans = 0
	for i in fit:
		if w - i:
			ans += 1
	print(ans)


from collections import deque
import sys
inf = float('inf')
input = sys.stdin.readline
import math
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	widths = list(map(int, input().split()))
	counts = [0] * 20
	for width in widths:
		counts[int(math.log2(width))] += 1
	space = w
	height = 1
	for it in range(n):
		largest = -1
		for (size, count_width) in list(enumerate(counts))[::-1]:
			if counts[size] > 0 and 2 ** size <= space:
				largest = size
				break
		if largest == -1:
			space = w
			height += 1
			for (size, count_width) in list(enumerate(counts))[::-1]:
				if counts[size] > 0 and 2 ** size <= space:
					largest = size
					break
		assert largest != -1
		counts[largest] -= 1
		space -= 2 ** largest
	print(height)


for _ in range(int(input())):
	(_, largura_caixa) = map(int, input().split(' '))
	frequencia = {}
	for retangulo in list(map(int, input().split(' '))):
		if not retangulo in frequencia:
			frequencia[retangulo] = 1
		else:
			frequencia[retangulo] = frequencia[retangulo] + 1
	retangulos = set(frequencia.keys())
	retangulos_usados = set()
	soma_linha = 0
	conta_linhas = 0
	while len(retangulos_usados) < len(retangulos):
		retangulos_restantes = [ret for ret in retangulos if not ret in retangulos_usados]
		retangulos_restantes.sort(reverse=True)
		for retangulo in retangulos_restantes:
			espaco_restante_linha = largura_caixa - soma_linha
			max_num_retangulos_linha = espaco_restante_linha // retangulo
			num_retangulos = min(frequencia[retangulo], max_num_retangulos_linha)
			soma_linha += num_retangulos * retangulo
			frequencia[retangulo] -= num_retangulos
			if frequencia[retangulo] == 0:
				retangulos_usados.add(retangulo)
		conta_linhas += 1
		soma_linha = 0
	print(conta_linhas)


from collections import Counter
pows = {}
p2 = {}
i = 0
x = 1
while x < 10 ** 9:
	pows[x] = i
	p2[i] = x
	x *= 2
	i += 1
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	a = [pows[x] for x in map(int, input().split())]
	c = Counter(a)
	done = 0
	ans = 0
	left = w
	while done != len(a):
		for x in sorted(c.keys(), reverse=True):
			while c[x] > 0 and p2[x] <= left:
				left -= p2[x]
				c[x] -= 1
				done += 1
		ans += 1
		left = w
	print(ans)


t = int(input())
from collections import Counter
for _ in range(t):
	(n, w) = map(int, input().split())
	arr = list(map(int, input().split()))
	d = Counter(arr)
	v = sorted(d.keys(), reverse=True)
	ans = 0
	while n:
		m = w
		for i in v:
			while d[i] and m >= i:
				d[i] -= 1
				m -= i
				n -= 1
		ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, W) = map(int, input().split(' '))
	length = W.bit_length()
	freq = [0] * length
	for w in map(int, input().split(' ')):
		freq[w.bit_length() - 1] += 1
	count = 0
	while n > 0:
		cur = W
		j = length - 1
		power_of_two = 1 << j
		while j >= 0:
			while freq[j] > 0 and cur >= power_of_two and (n > 0):
				freq[j] -= 1
				n -= 1
				cur -= power_of_two
			if n == 0:
				break
			j -= 1
			power_of_two = power_of_two >> 1
		count += 1
	print(count)


from collections import Counter
tcs = int(input())
for tc in range(tcs):
	(n, w) = list(map(int, input().split()))
	li = list(map(int, input().split()))
	di = Counter(li)
	s = sum(li)
	ans = 0
	le = len(li)
	c = 0
	while c < le:
		an = w
		for i in range(22, -1, -1):
			while an > 0 and an >= 1 << i and (di[1 << i] > 0):
				an -= 1 << i
				di[1 << i] -= 1
				c += 1
		ans += 1
		an = w
	print(ans)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	for j in l:
		if j in d:
			d[j] += 1
		else:
			d[j] = 1
	r = 0
	while d != {}:
		r += 1
		z = b
		for j in sorted(d.keys(), reverse=1):
			while d[j] > 0 and z >= j:
				z -= j
				d[j] -= 1
				if d[j] == 0:
					del d[j]
					break
	print(r)


def putin():
	return map(int, input().split())

def sol():
	(n, w) = putin()
	D = {}
	deg = 1
	while deg <= w:
		D[deg] = 0
		deg *= 2
	A = list(putin())
	for elem in A:
		D[elem] += 1
	max_deg = deg // 2
	cnt = 0
	while max_deg > 0:
		while max_deg > 0 and D[max_deg] == 0:
			max_deg //= 2
		if max_deg == 0:
			break
		cur = w
		cur_deg = max_deg
		while cur > 0 and cur_deg > 0:
			if cur_deg <= cur and D[cur_deg] > 0:
				cur -= cur_deg
				D[cur_deg] -= 1
			else:
				cur_deg //= 2
		cnt += 1
	print(cnt)
for iter in range(int(input())):
	sol()


rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
from collections import Counter
for _ in range(rn()):
	(n, W) = rns()
	w = rl()
	c = Counter(w)
	grid = n * [0]
	full = 0
	for num in sorted(c.keys(), reverse=True):
		j = full
		k = 0
		while k < c[num]:
			if grid[j] + num <= W:
				grid[j] += num
				if grid[j] == W:
					full += 1
					j += 1
				k += 1
			else:
				j += 1
	ans = len([i for i in grid if i > 0])
	print(ans)


from collections import Counter
for _ in range(int(input())):
	(_, W) = list(map(int, input().split()))
	boxes = list(map(int, input().split()))
	counts = Counter(boxes)
	max_power = max(counts.keys())
	levels = 0
	curr_w = W
	while counts:
		pow2 = max_power
		while curr_w > 0 and pow2 > 0:
			if curr_w >= pow2 and pow2 in counts:
				curr_w -= pow2
				counts[pow2] -= 1
				if counts[pow2] == 0:
					del counts[pow2]
			else:
				pow2 >>= 1
		levels += 1
		curr_w = W
	print(levels)


a = int(input())
from collections import OrderedDict
for s in range(a):
	x = list(map(int, input().strip().split()))[:2]
	n = x[0]
	w = x[1]
	mapa = {}
	larguras = list(map(int, input().strip().split()))[:n]
	for i in range(n):
		mapa[larguras[i]] = 0
	for i in range(n):
		mapa[larguras[i]] += 1
	mapa = OrderedDict(sorted(mapa.items(), reverse=True))
	resposta = 0
	while n > 0:
		restante = w
		for key in mapa.keys():
			while key <= restante and restante != 0 and (mapa[key] > 0):
				n -= 1
				restante -= key
				mapa[key] -= 1
		resposta += 1
	print(resposta)


import bisect
import math
alpha = 'abcdefghijklmnopqrstuvwxyz'
inf = 1e+17
mod = 998244353

def solve(n, arr, w):
	cnt = []
	for i in range(31):
		cnt.append(0)
	for j in range(n):
		cnt[int(math.log(arr[j], 2))] += 1
	answer = 0
	while cnt != [0] * 31:
		space = w
		ptr = 30
		while space and ptr > -1:
			while cnt[ptr] and space >= 2 ** ptr:
				space -= 2 ** ptr
				cnt[ptr] -= 1
			ptr -= 1
		answer += 1
	return answer
	pass
t = int(input())
ans = []
for _ in range(t):
	(n, w) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	ans.append(solve(n, arr, w))
for i in range(t):
	print(ans[i])


from collections import Counter
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	dct = dict(Counter(arr))
	ct = 0
	while n > 0:
		rl = w
		for x in dct:
			while x <= rl and dct[x] > 0:
				rl -= x
				n -= 1
				dct[x] -= 1
		ct += 1
	print(ct)


import sys
from sys import stdin
tt = int(stdin.readline())
ANS = []
pt = {}
for i in range(30):
	pt[2 ** i] = i
for loop in range(tt):
	(n, W) = map(int, stdin.readline().split())
	x = list(map(int, stdin.readline().split()))
	lis = [0] * 30
	for i in x:
		lis[pt[i]] += 1
	l = 0
	r = n
	while r - l != 1:
		m = (l + r) // 2
		rem = [0] * 30
		for i in range(30):
			if 2 ** i & W > 0:
				rem[i] += m
		for i in range(29, -1, -1):
			if rem[i] < lis[i]:
				break
			else:
				rem[i] -= lis[i]
				rem[i - 1] += rem[i] * 2
		else:
			r = m
			continue
		l = m
	ANS.append(str(r))
print('\n'.join(ANS))


from heapq import heappop, heappush
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort(reverse=True)
	cu = 0
	heap = []
	for r in a:
		if cu + r <= w:
			cu += r
		elif heap and heap[0] + r <= w:
			val = heappop(heap)
			val += r
			heappush(heap, val)
		else:
			heappush(heap, cu)
			cu = r
	if cu:
		print(len(heap) + 1)
	else:
		print(len(heap))


from collections import Counter
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	arr = list(map(int, input().split()))
	counter = Counter(arr)
	li = sorted(list(counter.keys()), reverse=True)
	ans = 0
	while n > 0:
		ans += 1
		curr = w
		for i in li:
			many = min(curr // i, counter[i])
			curr -= many * i
			counter[i] -= many
			n -= many
	print(ans)


from heapq import heappop, heappush
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	a = []
	heappush(a, -w)
	for i in l[::-1]:
		t = heappop(a)
		if i <= -t:
			heappush(a, i + t)
		else:
			heappush(a, t)
			heappush(a, -w + i)
	print(len(a))


from sys import stdin
from math import gcd

def gc(x):
	x1 = 0
	for i in str(x):
		x1 += int(i)
	return gcd(x, x1)
p2 = [pow(2, i) for i in range(22)]
T = int(stdin.readline().strip())
from math import log2
cnt = [0 for i in range(22)]
for t1 in range(T):
	(n, m) = map(int, stdin.readline().strip().split())
	s = list(map(int, stdin.readline().strip().split()))
	s.sort()
	for i in s:
		cnt[int(log2(i))] += 1
	ans = 0
	while max(cnt) != 0:
		ans += 1
		tot = m
		for i in range(21, -1, -1):
			while tot >= p2[i] and cnt[i] > 0:
				tot -= p2[i]
				cnt[i] -= 1
	print(ans)


import math

def main_function():
	test_cases = range(int(input()))
	for test_case in test_cases:
		(n, w) = [int(i) for i in input().split(' ')]
		b = sorted([int(i) for i in input().split(' ')], reverse=True)
		numbers = len(b)
		hashy = {}
		for i in b:
			if i in hashy:
				hashy[i] += 1
			else:
				hashy[i] = 1
		current_basket = 0
		counter = 0
		while numbers > 0:
			for i in hashy:
				if hashy[i] > 0:
					while w - current_basket >= i and hashy[i] > 0:
						current_basket += i
						hashy[i] -= 1
						numbers -= 1
						if numbers == 0:
							break
					if numbers == 0:
						break
			if current_basket > 0:
				counter += 1
			current_basket = 0
		print(counter)
main_function()


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	w = list(map(int, input().split()))
	w.sort()
	w.reverse()
	ans = []
	prev = 0
	prevpoint = 0
	for i in w:
		if i != prev:
			flag = 0
			for j in range(len(ans)):
				if ans[j] >= i:
					ans[j] -= i
					flag = 1
					prevpoint = j
					break
			if not flag:
				ans.append(m - i)
				prevpoint = len(ans) - 1
			prev = i
		else:
			flag = 0
			for j in range(prevpoint, len(ans)):
				if ans[j] >= i:
					ans[j] -= i
					flag = 1
					prevpoint = j
					break
			if not flag:
				ans.append(m - i)
				prevpoint = len(ans) - 1
			prev = i
	print(len(ans))


import math
for i in range(int(input())):
	(n, W) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	E = [0 for i in range(int(math.log(W, 2)) + 1)]
	for i in A:
		E[int(math.log(i, 2))] += 1
	U = [0 for i in range(int(math.log(W, 2)) + 1)]
	count = 0
	while E != U:
		e = W
		count += 1
		while True:
			d = int(math.log(e, 2))
			while E[d] == 0 and d != 0:
				d -= 1
			if d == 0:
				if E[0] > 0:
					E[0] -= 1
					e -= 1
				else:
					break
			else:
				E[d] -= 1
				e -= 2 ** d
			if e == 0:
				break
	print(count)


from collections import *
R = lambda : map(int, input().split())
(t,) = R()
while t:
	t -= 1
	(n, w) = R()
	c = Counter(R())
	r = 0
	while c:
		v = w
		r += 1
		for x in sorted(c)[::-1]:
			d = min(c[x], v // x)
			c[x] -= d
			v -= d * x
			if c[x] < 1:
				del c[x]
	print(r)


import sys
from math import log2
input = lambda : sys.stdin.readline().rstrip()
BITMAX = 21

class Problem:

	def __init__(self):
		pass

	def _get_largest(self, A, x):
		largest = -1
		for i in range(len(A) - 1, -1, -1):
			if A[i] > 0 and 2 ** i <= x:
				largest = i
				break
		return largest

	def solve(self):
		(N, W) = map(int, input().split())
		A = list(map(int, input().split()))
		bitcnt = [0] * BITMAX
		for a in A:
			bitcnt[int(log2(a))] += 1
		ans = 1
		rem = W
		i = 0
		while i < N:
			largest = self._get_largest(bitcnt, rem)
			if largest == -1:
				ans += 1
				rem = W
				continue
			rem = rem - 2 ** largest
			bitcnt[largest] -= 1
			i += 1
		print(ans)

def main():
	p = Problem()
	T = int(input())
	while T:
		p.solve()
		T -= 1
main()


from collections import Counter
import bisect
t = int(input())
for _ in range(t):
	(n, W) = map(int, input().split())
	s = list(map(int, input().split()))
	c = Counter(s)
	st = []
	for i in c:
		st.append((i, c[i]))
	st.sort()
	sv = []
	sf = []
	for i in st:
		sv.append(i[0])
		sf.append(i[1])
	ct = sum(sf)
	sp = W
	ht = 1
	while ct > 0:
		ind = bisect.bisect_right(sv, sp) - 1
		if ind == -1:
			ht += 1
			sp = W
		else:
			sf[ind] -= 1
			ct -= 1
			sp -= sv[ind]
			if sf[ind] == 0:
				sf.pop(ind)
				sv.pop(ind)
	print(ht)


def solution():
	(n, m) = map(int, input().split())
	nums = sorted(list(map(int, input().split())), reverse=True)
	dic = {}
	for i in nums:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	floor = 0
	while n > 0:
		rest = m
		for key in dic.keys():
			while dic[key] != 0 and rest >= key:
				rest -= key
				dic[key] -= 1
				n -= 1
		floor += 1
	print(floor)
t = int(input())
while t > 0:
	t -= 1
	solution()


test = int(input())
for counts in range(test):
	(n, w) = map(int, input().split())
	b = list(map(int, input().split()))
	b.sort(reverse=True)
	bs = []
	bl = []
	for i in b:
		if bs == [] or i < bs[-1]:
			bs.append(i)
			bl.append(1)
		else:
			bl[-1] += 1
	c = 0
	s = w
	while bs != []:
		c += 1
		s = w
		i = 0
		while i < len(bs):
			x = min(int(s / bs[i]), bl[i])
			s -= x * bs[i]
			bl[i] -= x
			if bl[i] == 0:
				bs.pop(i)
				bl.pop(i)
			else:
				i += 1
	print(c)


import math
T = int(input())
for t in range(T):
	(n, w) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	count = [0] * 20
	m = 0
	for i in arr:
		count[int(math.log(i, 2))] += 1
		m = max(i, m)
	ind = int(math.log(m, 2))
	z = 0
	i = ind
	curr = 0
	ans = 0
	pw = [2 ** i for i in range(20)]
	while z < n:
		if count[i] == 0:
			if i == 0:
				curr = 0
				ans += 1
				i = ind
			else:
				i -= 1
		elif curr + pw[i] > w:
			i -= 1
			pass
		else:
			curr += pw[i]
			count[i] -= 1
			z += 1
			if curr == w:
				ans += 1
				curr = 0
				i = ind
	if curr != 0:
		ans += 1
	print(ans)


import math, heapq
from collections import defaultdict
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	heap = [-w]
	heapq.heapify(heap)
	cnt = 1
	for i in range(n):
		top = -heapq.heappop(heap)
		if top > l[i]:
			top -= l[i]
			heapq.heappush(heap, -top)
		elif top == l[i]:
			if len(heap) == 0:
				if i == n - 1:
					continue
				heapq.heappush(heap, -w)
				cnt += 1
		else:
			cur = w - l[i]
			heapq.heappush(heap, -cur)
			heapq.heappush(heap, -top)
			cnt += 1
	print(cnt)


from collections import Counter
from typing import Iterator

def get_num_input() -> Iterator[int]:
	return map(int, input().split())

def main() -> None:
	width: int
	(_, width) = get_num_input()
	given: dict[int, int] = dict(sorted(Counter(get_num_input()).items(), reverse=True))
	level: int = 0
	while given:
		level += 1
		start: int = width
		unit: int
		count: int
		for (unit, count) in tuple(given.items()):
			if not start:
				break
			most_used: int
			(most_used, start) = divmod(start, unit)
			used: int = min(most_used, count)
			start += unit * (most_used - used)
			left: int = count - used
			if left:
				given[unit] = left
			else:
				del given[unit]
	print(level)
ONLY_ONCE: bool = False
for _ in range(1 if ONLY_ONCE else int(input())):
	main()


import math

def read_int():
	return int(input().strip())

def read_list(type=int):
	return list(map(type, input().strip().split()))

def get_next(a, capacity):
	n = len(a)
	right = n - 1
	left = 0
	while left < right:
		mid = (left + right) // 2
		if a[mid][0] > capacity:
			right = mid - 1
		elif a[mid][0] == capacity:
			right = mid
		else:
			left = mid
	if a[right][0] <= capacity:
		return right
	if a[left][0] <= capacity:
		return left
	return -1

def solve():
	ans = None
	(n, W) = read_list()
	a = read_list(int)
	assert n == len(a)
	count = [0 for i in range(20)]
	for i in range(n):
		count[int(math.log2(a[i]))] += 1
	ans = 0
	while True:
		if n == 0:
			break
		S = 0
		for i in range(19, -1, -1):
			while count[i] > 0 and S + math.pow(2, i) <= W:
				n -= 1
				S += math.pow(2, i)
				count[i] -= 1
		ans += 1
	return ans
T = int(input().strip())
for test_case in range(1, T + 1, 1):
	output = solve()
	print(output)


t = int(input())
for i in range(t):
	(n, w) = list(map(int, input().split(' ')))
	l = list(map(int, input().split(' ')))
	l.sort(reverse=True)
	tamanho = w
	c = 0
	d = {}
	for i in l:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	while n > 0:
		for i in d:
			while d[i] > 0 and i <= tamanho:
				tamanho -= i
				d[i] -= 1
				n -= 1
		tamanho = w
		c += 1
	print(c)


for _ in range(int(input())):
	(_, largura_caixa) = map(int, input().split(' '))
	frequencia = {}
	for largura_retangulo in list(map(int, input().split(' '))):
		if not largura_retangulo in frequencia:
			frequencia[largura_retangulo] = 1
		else:
			frequencia[largura_retangulo] = frequencia[largura_retangulo] + 1
	retangulos_usados = set()
	largura_utilizada = 0
	conta_linhas = 0
	while len(retangulos_usados) < len(frequencia):
		retangulos_restantes = [ret for ret in frequencia.keys() if not ret in retangulos_usados]
		retangulos_restantes.sort(reverse=True)
		for largura_retangulo in retangulos_restantes:
			largura_restante = largura_caixa - largura_utilizada
			max_num_retangulos_linha = largura_restante // largura_retangulo
			num_retangulos = min(frequencia[largura_retangulo], max_num_retangulos_linha)
			largura_utilizada += num_retangulos * largura_retangulo
			frequencia[largura_retangulo] -= num_retangulos
			if frequencia[largura_retangulo] == 0:
				retangulos_usados.add(largura_retangulo)
		conta_linhas += 1
		largura_utilizada = 0
	print(conta_linhas)


def findFit(d, w, k):
	for i in k:
		if i <= w and d[i] > 0:
			return i
	return -1
for t in range(int(input())):
	(n, w) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	d = dict()
	for i in arr:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	level = 1
	wl = w
	c = n
	k = sorted(d.keys(), reverse=True)
	while c > 0:
		fit = findFit(d, wl, k)
		if fit == -1:
			level += 1
			wl = w
		else:
			d[fit] -= 1
			c -= 1
			wl -= fit
	print(level)


import sys, math
T = int(input())
for t in range(T):
	(n, W) = map(int, sys.stdin.readline().split())
	w = list(map(int, sys.stdin.readline().split()))
	powers = [0] * (int(math.log(max(w), 2)) + 1)
	for u in w:
		powers[int(math.log(u, 2))] += 1
	cnt = 0
	while sum(powers) > 0:
		l = W
		for i in range(len(powers) - 1, -1, -1):
			y = min(powers[i], l // 2 ** i)
			powers[i] -= y
			l -= 2 ** i * y
		cnt += 1
	print(cnt)


from heapq import *
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	h = [0]
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	for i in range(n):
		t = heappop(h)
		if t + l[i] <= w:
			heappush(h, t + l[i])
		else:
			heappush(h, l[i])
			heappush(h, t)
	print(len(h))


def solve():
	(n, w) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	mx = max(a)
	counter = dict()
	for i in a:
		if i in counter:
			counter[i] += 1
		else:
			counter[i] = 1
	h = 0
	while n > 0:
		h += 1
		use = w
		while True:
			if mx not in counter:
				mx = mx // 2
			elif counter[mx] == 0:
				mx = mx // 2
			else:
				break
		util = mx
		while util > 0 and use > 0:
			if util not in counter:
				util = util // 2
			elif counter[util] == 0:
				util = util // 2
			elif util > use:
				util = util // 2
			else:
				use -= util
				counter[util] -= 1
				n -= 1
	print(h)
for i in range(0, int(input())):
	solve()


from heapq import heappop, heappush
t = int(input())
for j in range(t):
	(n, w) = map(int, input().split())
	entrada = list(map(int, input().split()))
	entrada.sort()
	pilha = []
	heappush(pilha, -w)
	cont = 1
	for i in entrada[::-1]:
		topo = heappop(pilha)
		if i <= -topo:
			heappush(pilha, i + topo)
		else:
			heappush(pilha, topo)
			heappush(pilha, -w + i)
			cont += 1
	print(cont)


t = int(input())
for i in range(t):
	(n, L) = input().split()
	n = int(n)
	L = int(L)
	w = input().split()
	for i in range(len(w)):
		w[i] = int(w[i])
	w.sort(reverse=True)
	cnt = {}
	for i in range(len(w)):
		if i == 0 or w[i] != w[i - 1]:
			cnt.setdefault(w[i], 0)
		cnt[w[i]] += 1
	h = 0
	while n > 0:
		h += 1
		W = L
		for i in cnt.keys():
			while W >= i and cnt[i] > 0:
				W -= i
				cnt[i] -= 1
				n -= 1
	print(h)


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for tests in range(t):
	(n, W) = map(int, input().split())
	L = list(map(int, input().split()))
	C = Counter(L)
	ANS = 0
	while len(C) > 0:
		ANS += 1
		rest = W
		for i in range(30, -1, -1):
			while 1 << i in C and rest >= 1 << i:
				rest -= 1 << i
				C[1 << i] -= 1
				if C[1 << i] == 0:
					del C[1 << i]
	print(ANS)


def p(a, n, t):
	l = 0
	r = n
	if n == 0:
		return -1
	if t < a[l]:
		return -1
	while l + 1 < r:
		w = (l + r) // 2
		if a[w] < t:
			l = w
		if a[w] > t:
			r = w
		if a[w] == t:
			return w
	return l
a = []
t = int(input())
for i in range(t):
	a.clear()
	(n, m) = map(int, input().split())
	for i in map(int, input().split()):
		a.append(i)
	a.sort()
	ans = 0
	while len(a) > 0:
		s = 0
		n = len(a)
		s += a[n - 1]
		a.pop(n - 1)
		n -= 1
		e = p(a, n, m - s)
		while e > -1:
			s += a[e]
			a.pop(e)
			n -= 1
			e = p(a, n, m - s)
		ans += 1
	print(ans)


import sys
from collections import Counter
input = sys.stdin.readline
for _ in range(int(input().strip())):
	(N, W) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	arr.sort(reverse=True)
	C = Counter(arr)
	h = 0
	while N > 0:
		temp = W
		for i in C:
			while i <= temp and C[i] > 0:
				N -= 1
				temp -= i
				C[i] -= 1
		h += 1
	print(h)


from collections import *
R = lambda : map(int, input().split())
(t,) = R()
while t:
	t -= 1
	(n, w) = R()
	a = sorted(map(list, Counter(R()).items()))[::-1]
	r = 0
	while n:
		v = w
		r += 1
		for p in a:
			(x, y) = p
			d = min(y, v // x)
			p[1] -= d
			v -= d * x
			n -= d
	print(r)


for _ in range(int(input())):
	(n, w) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	dic = {}
	for i in arr:
		try:
			dic[i] += 1
		except:
			dic[i] = 1
	v = list(dic.keys())
	k = n
	ans = 0
	while k:
		ans += 1
		s = w
		while s >= 0:
			b = False
			minn = 10 ** 9
			t = 0
			for i in v:
				if i <= s:
					b = True
					if s - i < minn:
						minn = s - i
						t = i
			if b:
				s -= t
				k -= 1
				dic[t] -= 1
				if not dic[t]:
					v.remove(t)
			if not b:
				break
	print(ans)


import bisect
t = int(input())
while t > 0:
	(n, w) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	l.reverse()
	ans = []
	c = 0
	for j in l:
		i = bisect.bisect_left(ans, j)
		if i < len(ans):
			ans[i] = ans[i] - j
		else:
			ans.append(w - j)
			c += 1
	print(c)
	t = t - 1


t = int(input())
from collections import Counter
for i in range(t):
	(n, W) = tuple(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	c = Counter(w)
	ans = 0
	dl = []
	while n > 0:
		temp = W
		for j in c:
			if temp > 0:
				if temp // j < c[j]:
					req = temp // j
					temp -= j * req
					c[j] -= req
				else:
					req = c[j]
					temp -= c[j] * j
					dl.append(j)
				n -= req
			else:
				break
		for j in dl:
			c.pop(j)
		dl.clear()
		ans += 1
	print(ans)


for t in range(int(input())):
	(n, W) = [int(x) for x in input().split()]
	d = {}
	nums = [int(i) for i in input().split()]
	for i in nums:
		try:
			d[i] += 1
		except:
			d[i] = 1
	count = 0
	keys = list(d.keys())
	keys.sort(reverse=True)
	while n > 0:
		count += 1
		left = W
		for i in keys:
			if d[i] == 0:
				continue
			else:
				while True:
					if left >= i and d[i] > 0:
						d[i] -= 1
						n -= 1
						left -= i
					else:
						break
	print(count)


import collections
import math
t = int(input())
for _ in range(t):
	(n, w) = map(int, input().split())
	a = list(map(int, input().split()))
	c = collections.Counter(a)
	keys = sorted(c.keys(), reverse=True)
	res = []
	for k in keys:
		cur = c[k]
		for i in range(len(res)):
			if cur == 0:
				break
			h = min(cur, (w - res[i]) // k)
			cur -= h
			res[i] += k * h
		while cur > 0:
			h = min(cur, w // k)
			cur -= h
			res.append(h * k)
	print(len(res))


T = int(input())
for t in range(T):
	(n, W) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	pwrs = [[] for i in range(22)]
	new = 0
	freq = [0 for i in range(22)]
	for i in A:
		curpw = 0
		while i > 2 ** curpw:
			curpw += 1
		pwrs[curpw].append(i)
		freq[curpw] += 1
		if len(pwrs[curpw]) == 1:
			new += 1
	ans = 0
	curspace = W
	done = 0
	while done < new:
		removed = 0
		for candi in range(21, -1, -1):
			while freq[candi] > 0 and pwrs[candi][0] <= curspace:
				num = min(freq[candi], curspace // pwrs[candi][0])
				curspace -= pwrs[candi][0] * num
				freq[candi] -= num
				removed = 1
				if freq[candi] == 0:
					done += 1
		if not removed:
			ans += 1
			curspace = W
	print(ans + 1)


from collections import Counter
for i in range(int(input())):
	(n, w) = map(int, input().split())
	a = list(map(int, input().split()))
	x = Counter(a)
	s = sorted(x.keys(), reverse=True)
	ans = 0
	while n:
		v = w
		for j in s:
			while x[j] != 0 and v >= j:
				x[j] -= 1
				v -= j
				n -= 1
		ans += 1
	print(ans)


from collections import Counter
t = int(input())
for _ in range(t):
	(n, w) = map(int, input().split())
	a = [int(i) for i in input().split()]
	(di, res) = (Counter(a), 0)
	ke = sorted(di.keys(), reverse=True)
	while n:
		m = w
		for el in ke:
			if m < 1:
				break
			if di[el]:
				p = m // el
				mi = min(p, di[el])
				m -= mi * el
				di[el] -= mi
				n -= mi
		res += 1
	print(res)


import sys
import os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
depth = 1000005
mod = 1000000007
sys.setrecursionlimit(depth)
from math import inf
from collections import defaultdict
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	a = list(map(int, input().split()))
	d = defaultdict(lambda : 0)
	for e in a:
		d[e] += 1
	a = sorted(list(d.items()), key=lambda x: x[0], reverse=True)
	a = [[e[0], e[1]] for e in a]
	(c, n) = (0, len(a))
	while True:
		(curr, i) = (0, 0)
		while i < n:
			if a[i][1] and curr + a[i][0] <= w:
				curr += a[i][0]
				a[i][1] -= 1
			else:
				i += 1
		c += 1
		if all([e[1] == 0 for e in a]):
			break
	print(c)


from sys import stdin
from math import log2
input = lambda : stdin.readline().strip()
t = int(input())
for _ in range(t):
	(n, W) = map(int, input().split())
	ls = list(map(int, input().split()))
	d = []
	for i in range(20):
		d.append(0)
	for i in ls:
		d[int(log2(i))] += 1
	result = 0
	while True:
		tmp = W
		flag = False
		for i in range(19, -1, -1):
			if d[i] != 0:
				cnt = min(d[i], tmp // 2 ** i)
				tmp -= 2 ** i * cnt
				d[i] -= cnt
				flag = True
		if not flag:
			break
		else:
			result += 1
	print(result)


t = int(input())
for i in range(t):
	(n, w) = map(int, input().split())
	r = list(map(int, input().split()))
	r.sort(reverse=True)
	d = dict()
	for e in r:
		if e not in d:
			d[e] = 1
		else:
			d[e] += 1
	temp = w
	count = 0
	while n > 0:
		for key in d:
			while d[key] > 0 and key <= temp:
				temp -= key
				d[key] -= 1
				n -= 1
		temp = w
		count += 1
	print(count)


from sys import stdin
from collections import defaultdict
from dataclasses import dataclass

@dataclass
class NonsenseNode(object):
	val: int
	count: int
	next: 'NonsenseNode'

def fit_box(root, width):
	prev = root
	cur = root.next
	while cur is not None:
		count = min(cur.count, width // cur.val)
		cur.count -= count
		width -= count * cur.val
		if cur.count == 0:
			prev.next = cur.next
			cur = prev
		prev = cur
		cur = cur.next

def single_case():
	width = int(stdin.readline().split()[1])
	v = defaultdict(lambda : 0)
	for b in (int(x) for x in stdin.readline().split()):
		v[b] += 1
	sorted_keys = sorted(v.keys(), reverse=True)
	root = NonsenseNode(0, 0, None)
	cur = root
	for key in sorted_keys:
		node = NonsenseNode(key, v[key], None)
		cur.next = node
		cur = node
	height = 0
	while root.next is not None:
		height += 1
		fit_box(root, width)
	return height
case_count = int(stdin.readline())
for _ in range(case_count):
	print(single_case())


from sys import stdin, stdout
from collections import Counter, deque
it = lambda : int(stdin.readline())
st = lambda : stdin.readline().strip()
mp = lambda : map(int, stdin.readline().split())
lt = lambda : list(map(int, stdin.readline().split()))
slt = lambda : stdin.readline().split()
ot = lambda s: stdout.write(str(s) + '\n')
test = it()
for _ in range(test):
	(n, w) = mp()
	l = lt()
	sums = sum(l)
	c = Counter(l)
	l = [0] * 20
	for x in range(20):
		ab = 2 ** x
		l[x] = c[ab]
	ht = 0
	while sums > 0:
		wid = w
		for x in range(19, -1, -1):
			if wid <= 0:
				break
			if l[x] > 0 and wid > 0:
				ab = 2 ** x
				ip = wid // ab
				if ip > l[x]:
					wid -= l[x] * ab
					sums -= l[x] * ab
					l[x] = 0
				else:
					wid -= ip * ab
					sums -= ip * ab
					l[x] -= ip
		ht += 1
	ot(ht)


from math import *

def inp():
	return int(input())

def st1():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
z = {2 ** i: i for i in range(20)}
ha = [2 ** i for i in range(20)]
while t:
	t -= 1
	(n, w) = ma()
	a = lis()
	h = 0
	(i, j) = (0, n - 1)
	bits = [0 for i in range(20)]
	for i in range(n):
		bits[z[a[i]]] += 1
	co = n
	cur = 0
	while co > 0:
		for j in range(19, -1, -1):
			if w - cur <= 0 or bits[j] == 0 or co <= 0:
				continue
			v = (w - cur) // ha[j]
			v = min(v, bits[j])
			bits[j] -= v
			cur += v * ha[j]
			co -= v
		cur = 0
		h += 1
	print(h)


from functools import reduce
import os
import sys
from collections import *
from decimal import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]

def Ceil(a, b):
	return a // b + int(a % b > 0)
albhabet = 'abcdefghijklmnopqrstuvwxyz'
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	(n, k) = value()
	a = arr()
	d = defaultdict(int)
	res = []
	for i in a:
		if i not in d:
			res.append(i)
		d[i] += 1
	res.sort(reverse=True)
	ans = 0
	while True:
		val = k
		rem = []
		for i in res:
			if val - i >= 0:
				no = min(d[i], val // i)
				d[i] -= no
				val -= i * no
				if d[i] == 0:
					rem.append(i)
		for i in rem:
			res.remove(i)
		ans += 1
		if len(res) == 0:
			break
	print(ans)


from collections import Counter
for test in range(int(input())):
	(n, w) = map(int, input().split())
	dct = Counter(list(map(int, input().split())))
	lst = sorted(list(map(list, dct.items())), reverse=True)
	h = 0
	while len(lst) != 0:
		width = 0
		h += 1
		for i in range(len(lst)):
			store = (w - width) // lst[i][0]
			if lst[i][1] >= store:
				width += lst[i][0] * store
				lst[i][1] -= store
			else:
				width += lst[i][1] * lst[i][0]
				lst[i][1] = 0
			if width == w:
				break
		i = 0
		while i != len(lst):
			if lst[i][1] == 0:
				del lst[i]
			else:
				i += 1
	print(h)


from collections import defaultdict
for _ in range(int(input())):
	(n, W) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))
	d = defaultdict(int)
	for i in l:
		d[i] += 1
	c = 0
	d = dict(sorted(d.items(), reverse=True))
	keys = list(d.keys())
	values = list(d.values())
	a = 0
	while sum(values):
		a = 0
		d = False
		for i in range(len(keys)):
			while values[i]:
				if keys[i] + a <= W:
					a += keys[i]
					values[i] -= 1
				else:
					break
		c += 1
	print(c)


import math
t = int(input())
for i in range(t):
	(n, w) = map(int, input().split())
	e = list(map(int, input().split()))
	t = [0] * 21
	dic1 = {}
	for i in e:
		index = int(math.log(i, 2))
		if index not in dic1:
			t[index] = 1
			dic1[index] = i
		else:
			t[index] += 1
	index1 = 20
	counter = 0
	while dic1:
		try:
			while t[index1] > 0:
				if index1 in dic1:
					target = w - dic1[index1]
				t[index1] -= 1
				for i in range(index1, -1, -1):
					while target >= 2 ** i and t[i] > 0:
						target -= 2 ** i
						t[i] -= 1
					if target == 0:
						break
				counter += 1
		except:
			pass
		if index1 in dic1:
			del dic1[index1]
		index1 -= 1
		if index1 == -1:
			break
	print(counter)


import bisect, sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	(values, loc) = (sorted([int(i) for i in input().split()], reverse=True), [])
	for value in values:
		i = bisect.bisect_left(loc, value)
		if i < len(loc):
			loc[i] -= value
		else:
			loc.append(w - value)
	print(len(loc))


def solve(n, w, arr):
	dict = {}
	for i in arr:
		dict[i] = dict.get(i, 0) + 1
	keys = list(dict.keys())
	keys.sort(reverse=True)
	count = 0
	i = 0
	temp = w
	while i < len(arr):
		for j in keys:
			while dict[j] > 0 and temp - j >= 0:
				dict[j] -= 1
				temp -= j
				i += 1
		temp = w
		count += 1
	return count
t = int(input())
for i in range(t):
	(n, w) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	print(solve(n, w, arr))


import bisect
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	ans = 0
	x = []
	for i in range(n - 1, -1, -1):
		if len(x) == 0:
			ans += 1
			bisect.insort(x, w)
		if x[-1] < l[i]:
			ans += 1
			bisect.insort(x, w - l[i])
		else:
			t = x.pop()
			bisect.insort(x, t - l[i])
	print(ans)


from sys import stdin
from math import log2, ceil
from collections import Counter

def convert_num_to_bin(x):
	string = bin(x)[2:]
	return [i for i in range(len(string)) if string[-1 - i] == '1']
t = int(stdin.readline().rstrip())
for _ in range(t):
	(n, w) = list(map(int, stdin.readline().rstrip().split()))
	w_arr = [int(log2(int(i))) for i in stdin.readline().rstrip().split()]
	count = Counter(w_arr)
	height = 0
	while n > 0:
		w1 = w
		i = max(count.keys())
		while w1 > 0 and i >= 0:
			bonk = min(w1 // pow(2, i), count[i])
			w1 -= bonk * pow(2, i)
			count[i] -= bonk
			i -= 1
			n -= bonk
		height += 1
	print(height)


from collections import *
R = lambda : map(int, input().split())
(t,) = R()
while t:
	t -= 1
	(n, w) = R()
	a = sorted(map(list, Counter(R()).items()))[::-1]
	r = 0
	while n:
		v = w
		r += 1
		i = 0
		while i < len(a):
			(x, y) = p = a[i]
			d = min(y, v // x)
			p[1] -= d
			v -= d * x
			n -= d
			if p[1]:
				i += 1
			else:
				del a[i]
	print(r)


from math import ceil
from math import floor
from random import random
from math import gcd

def ar():
	return [int(x) for x in input().split()]
T = 1
T = int(input())
size = 2 ** 20 + 7
dp = [0] * size
for t in range(T):
	(N, W) = ar()
	A = ar()
	for i in A:
		dp[i] += 1
	ans = 0
	while N > 0:
		curr = W
		i = 2 ** 20
		while i > 0:
			while dp[i] > 0 and curr >= i:
				dp[i] -= 1
				curr -= i
				N -= 1
			i //= 2
		ans += 1
	print(ans)


import sys
from os import path
if path.exists('inp.txt'):
	sys.stdin = open('inp.txt', 'r')
	sys.stdout = open('out.txt', 'w')
from collections import Counter
t = int(input())
while t:
	t -= 1
	(n, w) = map(int, input().split())
	li = list(map(int, input().split()))
	li.sort()
	omp = Counter(li)
	r = 0
	while omp != {}:
		r += 1
		h = w
		for j in sorted(omp.keys(), reverse=1):
			while omp[j] > 0 and h >= j:
				h -= j
				omp[j] -= 1
				if omp[j] == 0:
					del omp[j]
					break
	print(r)


from bisect import bisect
from collections import Counter
from sys import stdin, gettrace
if gettrace():

	def inputi():
		return input()
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	(n, bw) = map(int, input().split())
	ww = [int(a) for a in input().split()]
	wwc = sorted(Counter(ww).items(), reverse=True)
	wr = []
	for (w, c) in wwc:
		i = 0
		while c > 0:
			if i == len(wr):
				wr.append(bw)
			r = min(wr[i] // w, c)
			wr[i] -= r * w
			c -= r
			i += 1
	print(len(wr))

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


from math import log2

def solve_tc():
	(n, w) = list(map(int, input().split()))
	widths = list(map(int, input().split()))
	counts = [0 for _ in range(20)]
	for width in widths:
		counts[int(log2(width))] += 1
	space = w
	height = 1
	for it in range(n):
		largest = -1
		for (size, count_width) in list(enumerate(counts))[::-1]:
			if counts[size] > 0 and 2 ** size <= space:
				largest = size
				break
		if largest == -1:
			space = w
			height += 1
			for (size, count_width) in list(enumerate(counts))[::-1]:
				if counts[size] > 0 and 2 ** size <= space:
					largest = size
					break
		assert largest != -1
		counts[largest] -= 1
		space -= 2 ** largest
	print(height)
t = int(input())
while t > 0:
	t -= 1
	solve_tc()


import math, bisect
for t in range(int(input())):
	(n, w) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort()
	a = a[::-1]
	b = [w]
	x = 0
	for i in a:
		if i > b[x]:
			x += 1
			b.append(w)
		b[x] -= i
		y = b.pop()
		bisect.insort(b, y)
	print(len(b))


from math import log2

def largest_pow(cnt, n):
	i = min(len(cnt) - 1, int(log2(n)))
	for i in range(i, -1, -1):
		if cnt[i]:
			return 1 << i

def box(l, w, n):
	cnt = [0 for _ in range(int.bit_length(max(l)))]
	for i in l:
		cnt[int.bit_length(i) - 1] += 1
	remain = w
	res = 1
	boxes = n
	while boxes:
		if remain == 0:
			res += 1
			remain = w
		box = largest_pow(cnt, remain)
		if box != None:
			remain -= box
			boxes -= 1
			cnt[int.bit_length(box) - 1] -= 1
		else:
			res += 1
			remain = w
	return res
tests = int(input())
for _ in range(tests):
	(n, w) = tuple(map(int, input().split(' ')))
	l = list(map(int, input().split(' ')))
	print(box(l, w, n))


t = int(input())
for k in range(t):
	(n, w) = map(int, input().split())
	arr = list(map(int, input().split()))
	dict = {}
	for i in arr:
		if dict.get(i) == None:
			dict[i] = 1
		else:
			dict[i] += 1
	key = list(dict.keys())
	key.sort(reverse=True)
	c = 0
	temp = w
	ans = 0
	while c < len(arr):
		for i in key:
			while i <= temp and dict[i] > 0:
				temp -= i
				c += 1
				dict[i] -= 1
		temp = w
		ans += 1
	print(ans)


from collections import Counter
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	w1 = list(map(int, input().split()))
	w1.sort(reverse=True)
	d = dict(Counter(w1))
	h = 0
	while n > 0:
		k = w
		for i in d:
			while i <= k and d[i] > 0:
				n -= 1
				k -= i
				d[i] -= 1
		h += 1
	print(h)


from collections import *
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	l = list(map(int, input().split()))
	C = Counter(l)
	height = 0
	while len(C) > 0:
		height += 1
		rest = w
		for i in range(30, -1, -1):
			while 1 << i in C and rest >= 1 << i:
				rest -= 1 << i
				C[1 << i] -= 1
				if C[1 << i] == 0:
					del C[1 << i]
	print(height)


from sys import *
from math import *
from bisect import *
t = stdin.readline
R = range
p = stdout.write
mod = int(1000000000.0) + 7

def S():
	return t().strip()

def I():
	return int(t())

def GI():
	return map(int, input().strip().split())

def GS():
	return map(str, t().strip().split())

def IL():
	return list(map(int, t().strip().split()))

def SL():
	return list(map(str, t().strip().split()))
for _ in range(I()):
	(n, W) = GI()
	w = sorted(IL(), reverse=True)
	rem = [W] * n
	for i in range(n):
		idx = bisect_left(rem, w[i])
		rem[idx] -= w[i]
	print(n - rem.count(W))


import sys, math
input = sys.stdin.readline
from collections import defaultdict
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	ans = 0
	v = list(map(int, input().split()))
	d = defaultdict(int)
	vis = []
	for i in v:
		d[i] += 1
		if d[i] == 1:
			vis.append(i)
	vis.sort(reverse=True)
	cnt = 0
	while cnt < n:
		cur = 0
		i = 0
		while i < len(vis):
			if d[vis[i]] > 0:
				if cur + vis[i] <= w:
					cnt += 1
					cur += vis[i]
					d[vis[i]] -= 1
					i -= 1
			i += 1
		ans += 1
	print(ans)


import sys
input = sys.stdin.readline
from collections import defaultdict

def main():
	(n, W) = map(int, input().split())
	wlst = list(map(int, input().split()))
	dd = defaultdict(int)
	le = W.bit_length()
	cnt = [0] * le
	for w in wlst:
		cnt[w.bit_length() - 1] += 1

	def ok(x):
		tmp = 0
		for i in range(le - 1, -1, -1):
			if W >> i & 1:
				tmp += x
			tmp -= cnt[i]
			if tmp < 0:
				return False
			tmp *= 2
		return True
	l = 0
	r = n
	while r - l > 1:
		mid = (r + l) // 2
		if ok(mid):
			r = mid
		else:
			l = mid
	print(r)
for _ in range(int(input())):
	main()


import math

def setBitNumber(n):
	if n == 0:
		return 0
	msb = 0
	n = int(n / 2)
	while n > 0:
		n = int(n / 2)
		msb += 1
	return 1 << msb
t = int(input())
for _ in range(t):
	(n, w) = map(int, input().split())
	l = list(map(int, input().split()))
	d = dict()
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	ans = 0
	while n > 0:
		x = w
		ans += 1
		while x > 0:
			y = setBitNumber(x)
			while not (y in d and d[y] > 0):
				y = y // 2
				if y == 0:
					break
			if y == 0 or y > x:
				break
			else:
				x -= y
				n -= 1
				d[y] -= 1
	print(ans)


test = int(input())

def log2(n):
	s = 0
	while n:
		s += 1
		n //= 2
	return s - 1
for t in range(test):
	a = []
	for i in range(20):
		a.append(0)
	(n, w) = [int(i) for i in input().split(' ')]
	wa = [int(i) for i in input().split(' ')]
	for e in wa:
		a[log2(e)] += 1
	h = 0
	while sum(a):
		h += 1
		l = w
		i = 19
		while i >= 0:
			if a[i]:
				if 2 ** i <= l:
					l -= 2 ** i
					a[i] -= 1
					continue
			i -= 1
	print(h)


def test(n, w, a):
	q = {}
	s = 0
	for i in range(n):
		s += a[i]
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	a = list(set(a))
	a.sort(reverse=True)
	l = len(a)
	count = 0
	while s > 0:
		d = w
		if s < w:
			count += 1
			break
		i = 0
		while i < l:
			if q[a[i]] > 0 and a[i] <= d and (d != 0):
				q[a[i]] -= 1
				s -= a[i]
				d -= a[i]
				if d >= a[i]:
					i -= 1
			i += 1
			if d == 0:
				break
		count += 1
	print(count)
t = int(input())
for i in range(t):
	r = list(map(int, input().rstrip().split()))
	n = r[0]
	w = r[1]
	a = list(map(int, input().rstrip().split()))
	test(n, w, a)


import os
import sys
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
from collections import Counter

def main():
	for _ in range(int(input())):
		(n, W) = map(int, input().split())
		w = list(map(int, input().split()))
		d = Counter(w)
		l = list(d.keys())
		l.sort()
		l = l[::-1]
		ans = 1
		ln = len(l)
		i = 0
		w = W
		while d:
			flag = 0
			while l[i] not in d:
				i = (i + 1) % ln
				if i == 0:
					ans += 1
					w = W
					flag = 1
					break
			if flag:
				continue
			temp = w // l[i]
			if temp == 0:
				while temp == 0:
					i = (i + 1) % ln
					if i == 0:
						ans += 1
						flag = 1
						w = W
						break
					elif l[i] in d:
						temp = w // l[i]
				if flag:
					continue
			if temp >= d[l[i]]:
				w -= d[l[i]] * l[i]
				d.pop(l[i])
			else:
				d[l[i]] -= temp
				w -= temp * l[i]
			i = (i + 1) % ln
		print(ans)

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


for _ in range(int(input())):
	(n, w) = map(int, input().split())
	l = list(map(int, input().split()))
	l = sorted(l, reverse=True)
	d = dict()
	for i in l:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	w2 = w
	h = 0
	while n > 0:
		for j in d:
			while d[j] > 0 and j <= w2:
				w2 -= j
				d[j] -= 1
				n -= 1
		h += 1
		w2 = w
	print(h)


import sys
import heapq
input = sys.stdin.readline
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	heap = []
	ans = 1
	heapq.heappush(heap, -(w - a[n - 1]))
	for i in range(n - 2, -1, -1):
		tmp = -heapq.heappop(heap)
		if tmp >= a[i]:
			heapq.heappush(heap, -(tmp - a[i]))
		else:
			ans += 1
			heapq.heappush(heap, -tmp)
			heapq.heappush(heap, -(w - a[i]))
	print(ans)


import sys
input = sys.stdin.readline
from bisect import bisect
from collections import Counter
t = int(input())
for _ in range(t):
	(n, w) = map(int, input().split())
	c = Counter(list(map(int, input().split())))
	width = sorted(c.keys())
	ans = 1
	x = width[-1]
	c[x] -= 1
	if c[x] == 0:
		width.pop()
	curr = w - x
	while width:
		idx = bisect(width, curr)
		val = width[idx - 1]
		if val > curr:
			curr = w - val
			c[val] -= 1
			if c[val] == 0:
				del width[idx - 1]
			ans += 1
		else:
			curr -= val
			c[val] -= 1
			if c[val] == 0:
				del width[idx - 1]
	print(ans)


from io import BytesIO, IOBase
import sys
import math
import os
from collections import defaultdict
from math import ceil
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def mint():
	return map(int, input().split())

def mfloat():
	return map(float, input().split())

def solve():
	(n, w) = mint()
	(*a,) = mint()
	d = {}
	for i in a:
		d[i] = d.get(i, 0) + 1
	vals = sorted(d.keys(), reverse=True)
	remaining = [w] * n
	ans = 0
	for i in vals:
		level = 0
		while remaining[level] < i:
			level += 1
		while d[i]:
			take = min(d[i], remaining[level] // i)
			d[i] -= take
			remaining[level] -= take * i
			ans = max(ans, level)
			level += 1
	print(ans + 1)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from heapq import heapify, heappush as hp, heappop as p
for t in range(int(input())):
	(n, w) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	h = []
	heapify(h)
	hp(h, l.pop())
	while len(l):
		a = l.pop()
		b = p(h)
		if b + a <= w:
			b += a
			hp(h, b)
		else:
			hp(h, a)
			hp(h, b)
	print(len(h))


for _ in range(int(input())):
	(n, w) = map(int, input().split())
	a = list(map(int, input().split()))
	s = set()
	for i in a:
		s.add(i)
	s = list(s)
	s.sort(reverse=True)
	sum = 0
	ans = 0
	ar = [0] * (n + 1)
	f = {}
	for i in a:
		if i in f:
			f[i] += 1
		else:
			f[i] = 1
	for i in s:
		idx = 0
		count = 0
		while True:
			if count == f[i]:
				break
			if ar[idx] + i <= w:
				ar[idx] += i
				count += 1
			else:
				idx += 1
	idx = 0
	while True:
		if ar[idx] != 0:
			ans += 1
		else:
			break
		idx += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, w) = map(int, input().split())
	l_input = list(map(int, input().split()))
	l = sorted(l_input, reverse=True)
	d = {}
	for e in l:
		if e not in d:
			d[e] = 1
		else:
			d[e] += 1
	w_copy = w
	count = 0
	while n > 0:
		for e in d:
			while e <= w_copy and d[e] > 0:
				w_copy -= e
				d[e] -= 1
				n -= 1
		count += 1
		w_copy = w
	print(count)


import sys, math, itertools, random, bisect, heapq
from collections import defaultdict
INF = 10 ** 18

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
for _ in range(int(input())):
	(n, w) = get_ints()
	widths = get_array()
	counts = [0 for _ in range(20)]
	for width in widths:
		counts[int(math.log2(width))] += 1
	space = w
	height = 1
	for it in range(n):
		largest = -1
		for (size, count_width) in list(enumerate(counts))[::-1]:
			if counts[size] > 0 and 2 ** size <= space:
				largest = size
				break
		if largest == -1:
			space = w
			height += 1
			for (size, count_width) in list(enumerate(counts))[::-1]:
				if counts[size] > 0 and 2 ** size <= space:
					largest = size
					break
		assert largest != -1
		counts[largest] -= 1
		space -= 2 ** largest
	print(height)


import math
for _ in range(int(input())):
	(n, w) = map(int, input().split())
	arr = map(int, input().split())
	arr = list(arr)
	arr.sort(reverse=True)
	cnt = 0
	d = {}
	for i in arr:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	temp = w
	while n > 0:
		for i in d:
			while d[i] != 0 and i <= temp:
				d[i] -= 1
				temp -= i
				n -= 1
		cnt += 1
		temp = w
	print(cnt)


from collections import Counter, OrderedDict
for _ in range(int(input())):
	(n, W) = map(int, input().split())
	inp = list(map(int, input().split()))
	mp = OrderedDict(Counter(sorted(inp, reverse=True)))
	ans = 0
	while n > 0:
		w_left = W
		for w in mp:
			while w <= w_left and mp[w] > 0:
				w_left -= w
				mp[w] -= 1
				n -= 1
		ans += 1
	print(ans)


from collections import Counter
t = int(input())
for i in range(t):
	(n, w) = map(int, input().split())
	l = list(map(int, input().split()))
	x = Counter(l)
	y = sorted(x.keys())[::-1]
	s1 = 0
	s2 = 0
	while s2 < n:
		z = w
		for j in y:
			while x[j] != 0 and z >= j:
				x[j] = x[j] - 1
				z = z - j
				s2 = s2 + 1
		s1 = s1 + 1
	print(s1)


from sys import stdin, stdout
from collections import *
from math import gcd, ceil, floor
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')
Y = 'YES'
N = 'NO'

def solve():
	(n, W) = mp()
	w = li()
	cnt = Counter(w)
	ans = 0
	while n > 0:
		cur = W
		for i in sorted(cnt.keys(), reverse=True):
			while cnt[i] > 0 and cur >= i:
				cnt[i] -= 1
				n -= 1
				cur -= i
		ans += 1
	print(ans)
for test in range(int(input())):
	solve()