Chef came across a new online judge that has N problems, and decided that he wants to solve them.

Chef takes A_{i} consecutive minutes to solve the i-th problem, and will take a break of B_{i} minutes immediately after solving it.    
That is, Chef will solve a problem, then take a break. Solve another problem, then take another break, and so on.

Chef has K minutes of free time. If he chooses the problems and their order optimally, what is the maximum number of problems he can solve in this time?

Note that a problem is considered solved if Chef finishes solving it by the K-th minute, even if the break time of the last problem extends past minute K. See the sample tests below for an example.

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of three lines of input.
- The first line of each test case contains two space-separated integers N and K — the number of problems in the online judge and Chef's free time, respectively.
- The second line of each test case contains N space-separated integers — the values A_{1}, A_{2}, \ldots, A_{N}.
- The third line of each test case contains N space-separated integers — the values B_{1}, B_{2}, \ldots, B_{N}.

------ Output Format ------ 

For each test case, output on a new line the maximum number of problems that Chef can solve within K minutes.

------ Constraints ------ 

$1 ≤ T ≤ 2\cdot 10^{4}$
$1 ≤ N ≤ 2\cdot 10^{5}$
$1 ≤ K ≤ 10^{8}$
$1 ≤ A_{i} ≤ 10^{8}$
$0 ≤ B_{i} ≤ 10^{8}$
- The sum of $N$ over all test cases won't exceed $2\cdot 10^{5}$.

----- Sample Input 1 ------ 
4
3 10
3 4 5
2 4 2
3 8
3 4 5
2 4 2
5 20
23 54 124 54 83
2 9 5 2 10
5 20
4 7 12 34 13
30 4 3 0 9

----- Sample Output 1 ------ 
2
1
0
2

----- explanation 1 ------ 
Test case $1$: Chef can solve the first problem followed by the second problem.
- $3$ minutes for the first problem
- $2$ minutes of break time after solving it, for a total of $5$ minutes
- $5$ minutes for the third problem, for a total of $10$ minutes
- There's two minutes of break time left which goes beyond $10$ minutes, but that's ok: Chef finished solving $2$ problems within $10$ minutes.

Test case $2$: The same times as the first sample, but with $K = 8$. Now, Chef can solve any one problem, but cannot solve a second one no matter what.

Test case $3$: Chef can't solve anything within $20$ minutes.

Test case $4$: Chef can solve the third problem followed by the first problem.

Difficulty: MEDIUM_HARD

Solutions:
T = int(input())
for i in range(T):
	(n, k) = map(int, input().split())
	w = list(map(int, input().split()))
	t = list(map(int, input().split()))
	c = 0
	s = []
	for i in range(n):
		s.append(w[i] + t[i])
	s.sort()
	for i in range(n):
		if s[i] > k:
			break
		k -= s[i]
		c += 1
	if c != n:
		for j in range(n):
			if w[j] <= k:
				if k + t[j] >= s[i] or w[j] + t[j] >= s[i]:
					c += 1
					break
	print(c)


t = int(input())
while t:
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	T = list()
	for i in range(0, N):
		T.append((A[i] + B[i], i))
	T.sort()
	ans = 0
	maxs = 0
	for i in range(0, N):
		if T[i][0] > K:
			break
		ans += 1
		K -= T[i][0]
	if ans != N:
		for j in range(N):
			if A[j] <= K and (B[j] + A[j] >= T[i][0] or K + B[j] >= T[i][0]):
				ans += 1
				break
	print(ans)
	t = t - 1


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	s = list()
	for i in range(n):
		s.append(A[i] + B[i])
	s.sort()
	m_p = 0
	r = k
	for i in range(n):
		if s[i] > r:
			break
		r -= s[i]
		m_p += 1
	if m_p == n:
		ans = m_p
	else:
		for j in range(n):
			if A[j] <= r:
				if A[j] + B[j] >= s[i] or r + B[j] - s[i] >= 0:
					m_p += 1
					break
	print(m_p)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append(a[i] + b[i])
	c1 = c
	c.sort()
	count = 0
	for i in range(n):
		if c[i] > k:
			break
		k -= c[i]
		count += 1
	if count == n:
		print(count)
		continue
	for j in range(n):
		if a[j] <= k:
			if a[j] + b[j] >= c[i] or k + b[j] - c[i] >= 0:
				count += 1
				break
	print(count)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
mod = 1000000007

def solve(n, k, nums1, nums2):
	new = [nums1[i] + nums2[i] for i in range(n)]
	new.sort()
	count = 0
	for i in range(n):
		if new[i] > k:
			break
		else:
			count += 1
			k -= new[i]
	if count == n:
		ans = count
	else:
		for j in range(len(nums1)):
			if nums1[j] <= k and (nums1[j] + nums2[j] >= new[i] or k + nums2[j] >= new[i]):
				count += 1
				break
	return count
tried = int(input())
for _ in range(tried):
	(n, k) = mul()
	nums1 = seq()
	nums2 = seq()
	print(solve(n, k, nums1, nums2))


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append(x[i] + y[i])
	c.sort()
	cnt = 0
	for j in range(n):
		if c[j] <= k:
			k -= c[j]
			cnt += 1
		else:
			break
	if cnt == n:
		pass
	else:
		for e in range(n):
			if x[e] <= k:
				if x[e] + y[e] >= c[j] or y[e] + k >= c[j]:
					cnt += 1
					break
	print(cnt)


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	(A, B) = (list(t) for t in zip(*sorted(zip(A, B), key=lambda x: x[0] + x[1])))
	(time, ans, maxB) = (0, 0, 0)
	for i in range(N):
		if time + A[i] <= K:
			time += A[i] + B[i]
			maxB = max(maxB, B[i])
			ans += 1
	if ans != N and time <= K and (time - maxB + A[ans] + B[ans] <= K):
		ans += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, s) = map(int, input().split(' '))
	a = input().split(' ')
	b = input().split(' ')
	c = []
	for j in range(n):
		c.append((int(a[j]), int(b[j]), int(a[j]) + int(b[j])))
	c1 = sorted(c, key=lambda l: l[2])
	add = True
	k = 0
	sum = 0
	while add and k < n:
		if sum + c1[k][2] <= s:
			sum += c1[k][2]
			k += 1
		else:
			add = False
	if k == n:
		print(n)
	elif not add:
		asm = sorted(c1[k:], key=lambda l: l[0])[0]
		if asm[0] + sum <= s:
			print(k + 1)
		else:
			for k1 in range(k):
				if c1[k1][0] + sum - c1[k1][2] + c1[k][2] <= s:
					print(k + 1)
					break
			else:
				print(k)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append(a[i] + b[i])
	c.sort()
	d = 0
	for i in range(n):
		if k < c[i]:
			break
		k -= c[i]
		d += 1
	if d != n:
		for j in range(n):
			if a[j] <= k and (a[j] + b[j] >= c[i] or k + b[j] >= c[i]):
				d += 1
				break
	print(d)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [x + y for (x, y) in zip(a, b)]
	c.sort()
	count = 0
	for i in range(n):
		if k < c[i]:
			break
		count += 1
		k -= c[i]
	if count == n:
		pass
	else:
		for j in range(n):
			if a[j] <= k:
				if a[j] + b[j] >= c[i] or k + b[j] - c[i] >= 0:
					count += 1
					break
	print(count)


import queue
import math
case = int(input())
for _ in range(case):
	(n, k) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	brr = list(map(int, input().split(' ')))
	nrr = []
	for i in range(n):
		nrr.append((arr[i] + brr[i], arr[i], brr[i]))
	nrr.sort(key=lambda x: x[0])
	res = 0
	mx = 0
	for i in range(n):
		if k - nrr[i][0] >= 0:
			res += 1
			k -= nrr[i][0]
			mx = max(mx, nrr[i][2])
		else:
			break
	ans = res
	if k == 0 or res == n:
		print(res)
		continue
	else:
		mini = math.inf
		if nrr[i][0] <= k + mx:
			ans += 1
		while i < n:
			mini = min(mini, nrr[i][1])
			i += 1
		if mini <= k:
			res += 1
		print(max(res, ans))
		continue


import bisect
import math
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	assert len(a) == n
	assert len(b) == n
	c = [(x + y, x, y) for (x, y) in zip(a, b)]
	c.sort()
	tot_time = 0
	num_max = 0
	time_used = 0
	done = False
	over = False
	for (z, x, y) in c:
		if not over:
			tot_time += z
		if tot_time > k:
			over = True
			if time_used + x <= k:
				print(num_max + 1)
				done = True
				break
		else:
			num_max += 1
			time_used = tot_time
	if done:
		continue
	if not over:
		print(num_max)
		continue
	for (_, _, y) in c[:num_max]:
		if tot_time - y <= k:
			print(num_max + 1)
			done = True
			break
	if not done:
		print(num_max)
	continue


import sys, threading
import math
from os import path
from collections import deque, defaultdict, Counter
from bisect import *
from string import ascii_lowercase
from functools import cmp_to_key
from random import randint
from heapq import *
from array import array
from types import GeneratorType

def readInts():
	x = list(map(int, sys.stdin.readline().rstrip().split()))
	return x[0] if len(x) == 1 else x

def readList(type=int):
	x = sys.stdin.readline()
	x = list(map(type, x.rstrip('\n\r').split()))
	return x

def readStr():
	x = sys.stdin.readline().rstrip('\r\n')
	return x
write = sys.stdout.write
read = sys.stdin.readline
MAXN = 1123456

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

class mydict:

	def __init__(self, func=lambda : 0):
		self.random = randint(0, 1 << 32)
		self.default = func
		self.dict = {}

	def __getitem__(self, key):
		mykey = self.random ^ key
		if mykey not in self.dict:
			self.dict[mykey] = self.default()
		return self.dict[mykey]

	def get(self, key, default):
		mykey = self.random ^ key
		if mykey not in self.dict:
			return default
		return self.dict[mykey]

	def __setitem__(self, key, item):
		mykey = self.random ^ key
		self.dict[mykey] = item

	def getkeys(self):
		return [self.random ^ i for i in self.dict]

	def __str__(self):
		return f'{[(self.random ^ i, self.dict[i]) for i in self.dict]}'

def lcm(a, b):
	return a * b // math.gcd(a, b)

def mod(n):
	return n % 1000000007

def lower_bound(a, num):
	l = 0
	r = len(a) - 1
	ans = -1
	while l <= r:
		mid = (l + r) // 2
		if a[mid] <= num:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	return ans

def solve(t):
	(n, k) = readInts()
	ar = readList()
	br = readList()
	sar = []
	for i in range(n):
		sar.append((ar[i] + br[i], i))
	sar.sort()
	pref = []
	sm = 0
	for (num, ind) in sar:
		sm += num
		pref.append(sm)
	ans = 0
	for i in range(n):
		taken = sar[i][1]
		if ar[taken] > k:
			continue
		li = lower_bound(pref, k - ar[taken])
		cur = 1
		if li == -1:
			ans = max(ans, cur)
			continue
		cur += li + 1
		if i <= li:
			cur -= 1
			if li < len(sar) - 1 and pref[li] - sar[i][0] + sar[li + 1][0] <= k - ar[taken]:
				cur += 1
		ans = max(ans, cur)
	print(ans)

def main():
	t = 1
	if path.exists('/Users/arijitbhaumik/Library/Application Support/Sublime Text/Packages/User/input.txt'):
		sys.stdin = open('/Users/arijitbhaumik/Library/Application Support/Sublime Text/Packages/User/input.txt', 'r')
		sys.stdout = open('/Users/arijitbhaumik/Library/Application Support/Sublime Text/Packages/User/output.txt', 'w')
	t = readInts()
	for i in range(t):
		solve(i + 1)
main()


for i in range(int(input())):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = []
	for i in range(N):
		C.append(A[i] + B[i])
	C.sort()
	count = 0
	r = K
	for i in range(N):
		if C[i] > r:
			break
		r -= C[i]
		count += 1
	if count == N:
		print(count)
	else:
		for j in range(N):
			if A[j] <= r:
				if A[j] + B[j] >= C[i] or r + B[j] - C[i] >= 0:
					count += 1
					break
		print(count)


import bisect
import math
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	assert len(a) == n
	assert len(b) == n
	c = [x + y for (x, y) in zip(a, b)]
	c.sort()
	tot_time = 0
	prob_time = c[0]
	d = [(tot_time, prob_time, 0)]
	for i in range(n):
		if c[i] != prob_time:
			assert c[i] > prob_time
			d.append((tot_time, c[i], i))
			prob_time = c[i]
		tot_time += prob_time
	d.append((tot_time, math.inf, n))
	max_probs = 0
	for (aa, bb) in zip(a, b):
		t0 = k - aa
		if t0 < 0:
			continue
		t1 = k + bb
		i0 = bisect.bisect_right(d, (t0, math.inf, math.inf))
		i0 -= 1
		assert i0 >= 0
		if aa + bb >= d[i0][1]:
			num_probs = d[i0][2] + (t0 - d[i0][0]) // d[i0][1] + 1
		else:
			i1 = bisect.bisect_right(d, (t1, math.inf, math.inf))
			i1 -= 1
			assert aa + bb < d[i1][1]
			if d[i1][1] == math.inf:
				num_probs = n
			else:
				num_probs = d[i1][2] + (t1 - d[i1][0]) // d[i1][1]
		if num_probs > max_probs:
			max_probs = num_probs
	print(max_probs)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	s = []
	for i in range(n):
		s.append(a[i] + b[i])
	s.sort()
	count = 0
	r = k
	for i in range(n):
		if s[i] > r:
			break
		r -= s[i]
		count += 1
	if count == n:
		print(count)
	else:
		for j in range(n):
			if a[j] <= r:
				if a[j] + b[j] >= s[i] or r + b[j] - s[i] >= 0:
					count += 1
					break
		print(count)


t = int(input())
for _ in range(t):
	(q, t) = map(int, input().split())
	questions = [int(i) for i in input().split()]
	time = [int(i) for i in input().split()]
	d = {}
	for j in range(len(questions)):
		d[j] = [questions[j], time[j], questions[j] + time[j]]
	d = dict(sorted(d.items(), key=lambda x: x[1][2]))
	qs = 0
	summ = 0
	f = True
	mn = float('inf')
	mx_b = 0
	key = 0
	for (k, v) in d.items():
		summ += v[2]
		mx_b = max(mx_b, v[1])
		if summ - mx_b <= t:
			qs += 1
		else:
			summ -= v[2]
	print(qs)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	v = [[i, j] for (i, j) in zip(a, b)]
	v.sort(key=lambda x: (x[0] + x[1], -x[0]))
	mb = 0
	cur = 0
	ans = 0
	for i in range(n):
		if cur + v[i][0] <= k:
			ans += 1
			cur += sum(v[i])
			mb = max(mb, v[i][1])
	if ans != n and cur <= k and (cur - mb + sum(v[ans]) <= k):
		ans += 1
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(a, b) = (list(t) for t in zip(*sorted(zip(a, b), key=lambda x: x[0] + x[1])))
	(summ, count, maxb) = (0, 0, 0)
	for i in range(n):
		if summ + a[i] <= k:
			summ += a[i] + b[i]
			maxb = max(maxb, b[i])
			count += 1
	if count != n and summ <= k and (summ - maxb + a[count] + b[count] <= k):
		count += 1
	print(count)


from queue import PriorityQueue
from collections import Counter
import math
import bisect as bs
from collections import deque
op = int(input())
for _ in range(op):
	n = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(len(a)):
		c.append([a[i] + b[i], a[i], b[i]])
	c.sort()
	co = 0
	y = -1
	k = n[1]
	maxi = 0
	d = Counter(a)
	for i in range(len(c)):
		if c[i][0] <= k:
			co += 1
			k -= c[i][0]
			d[c[i][1]] -= 1
			maxi = max(maxi, c[i][2])
			if d[c[i][1]] == 0:
				d.pop(c[i][1])
		else:
			y = i
			break
	if y == -1:
		print(co)
	else:
		u = False
		maxi += k
		if c[y][0] <= maxi:
			u = True
			co += 1
			d[c[y][1]] -= 1
			if d[c[y][1]] == 0:
				d.pop(c[y][1])
			maxi -= c[y][0]
			print(co)
		if u == False:
			w = 10 ** 18
			for i in d:
				w = min(w, i)
			if w <= k:
				print(co + 1)
			else:
				print(co)


def fun(a):
	return a[0] + a[1]
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(a, b) = (list(t) for t in zip(*sorted(zip(a, b), key=fun)))
	(cur_sum, c, mxb) = (0, 0, 0)
	for i in range(n):
		if cur_sum + a[i] <= k:
			cur_sum += a[i] + b[i]
			mxb = max(mxb, b[i])
			c += 1
	if c != n and cur_sum <= k and (cur_sum - mxb + a[c] + b[c] <= k):
		c += 1
	print(c)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [(ai + bi, bi) for (ai, bi) in zip(a, b)]
	c.sort()
	(t, m, ans) = (0, 0, 0)
	for i in range(n):
		(t1, m1) = (t + c[i][0], max([m, c[i][1]]))
		if t1 <= k + m1:
			(t, m) = (t1, m1)
			ans += 1
	print(ans)


for tcase in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ab = [(ai + bi, ai, bi) for (ai, bi) in zip(a, b)]
	ab.sort()
	(t0, m0, i, ans) = (0, 0, 0, 0)
	for i in range(n):
		(t1, m1) = (t0 + ab[i][0], max(m0, ab[i][2]))
		if t1 <= k + m1:
			(t0, m0) = (t1, m1)
			ans += 1
	print(ans)


for tcase in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ab = [(ai + bi, ai, bi) for (ai, bi) in zip(a, b)]
	ab.sort()
	t = 0
	m = 0
	i = 0
	ans = 0
	for i in range(n):
		if t + ab[i][0] <= k + max(m, ab[i][2]):
			t += ab[i][0]
			m = max(m, ab[i][2])
			ans += 1
	print(ans)


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = [(A[i], B[i]) for i in range(N)]
	C.sort(key=sum)
	ans = 0
	for i in range(N):
		if sum(C[i]) <= K:
			ans += 1
			K -= sum(C[i])
		else:
			break
	else:
		print(ans)
		continue
	if min((x[0] for x in C[i:])) <= K:
		ans += 1
	elif i > 0:
		m = min((sum(x) for x in C[i:]))
		n = max((x[1] for x in C[:i]))
		if n >= m - K:
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	xx = list()
	for i in range(n):
		xx.append([a[i] + b[i], a[i], b[i]])
	xx = sorted(xx, key=lambda i: i[0])
	mmax = 0
	num = 0
	for i in xx:
		mmax = max(mmax, i[2])
		if i[0] <= x:
			x -= i[0]
			num += 1
		elif i[0] <= x + mmax:
			num += 1
			break
	print(num)


import math
from collections import Counter
from heapq import *

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

def nt():
	return int(input())

def st():
	return input()
yes = 'YES'
no = 'NO'
even = 'EVEN'
odd = 'ODD'
mod = 998244353

def prefix(L):
	size = len(L)
	for i in range(size - 1):
		L[i + 1] = L[i] + L[i + 1]
	return L

def exponentiation(bas, exp, mod):
	t = 1
	while exp > 0:
		if exp % 2 != 0:
			t = t * bas % mod
		bas = bas * bas % mod
		exp //= 2
	return t % mod

def binlist(x):
	L = [0] * 21
	temp = bin(x)
	temp = temp[2:]
	x = len(temp)
	indexL = []
	for i in range(x - 1, -1, -1):
		if temp[i] == '1':
			L[x - i] = 1
			indexL.append(x - i)
	return L

def binlisttoint(L):
	x = 0
	for i in range(1, 21):
		if L[i] == '1':
			x += 2 ** (i - 1)
	return x
for _ in range(int(input())):
	(n, k) = li()
	A = li()
	B = li()
	new = [[a + b, a, b] for (b, a) in zip(B, A)]
	new.sort()
	Q = []
	ans = 0
	res = 0
	for (c, a, b) in new:
		if c > k:
			if a <= k:
				res = max(res, ans + 1)
				break
			elif Q and k - Q[0] >= c:
				res = max(res, ans + 1)
				break
		else:
			ans += 1
			heappush(Q, -b)
			k -= c
	print(max(ans, res))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = []
	for f in range(n):
		l.append([a[f], b[f]])
	l.sort(key=lambda x: (sum(x), x[0]))
	mx = 0
	su = 0
	i = 0
	while i < n:
		if l[i][0] + l[i][1] + su <= m:
			su += l[i][0] + l[i][1]
			mx = max(mx, l[i][1])
			i += 1
		else:
			break
	x = [0] * n
	for j in range(n - 1, -1, -1):
		if j == n - 1:
			x[j] = l[j][0]
		else:
			x[j] = min(x[j + 1], l[j][0])
	ans = i
	if i < n:
		rem = m - su
		if x[i] <= rem:
			ans += 1
		elif rem + mx >= l[i][0] + l[i][1]:
			ans += 1
	print(ans)


import string
from functools import lru_cache
import atexit, io
import sys
from math import log2
import math
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right, insort
from math import gcd
from math import sqrt
from collections import Counter, defaultdict
from heapq import heappush, heappop, heapify
import heapq

class FenwickTree:

	def __init__(self, n):
		self.farr = [0] * (n + 1)

	def prefixSum(self, idx):
		s = 0
		while idx > 0:
			s += self.farr[idx]
			idx -= idx & -idx
		return s

	def update(self, idx, val):
		while idx < len(self.farr):
			self.farr[idx] += val
			idx += idx & -idx

	def find(self, k):
		curr = 0
		ans = 0
		prevSum = 0
		for i in range(log2(n), -1, -1):
			if self.farr[curr + (i << i)] + prevSum < k:
				curr += 1 << i
				prevSum += self.farr[curr]
		return curr + 1

class Trie(object):

	def __init__(self):
		self.trie = {}

	def insert(self, word):
		t = self.trie
		for c in word:
			if c not in t:
				t[c] = {}
			t = t[c]
		t['-'] = True

	def search(self, word):
		t = self.trie
		for c in word:
			if c not in t:
				return False
			t = t[c]
		return '-' in t

	def startsWith(self, prefix):
		t = self.trie
		for c in prefix:
			if c not in t:
				return False
			t = t[c]
		return True

	def query(self, word):
		ans = 0
		t = self.trie
		for i in word:
			if i not in t:
				break
			ans += 1
			t = t[i]
		return ans

class FenvTree:

	def __init__(self, arr):
		arr.insert(0, 0)
		self.farr = [0]
		prefix = [0]
		for i in arr[1:]:
			prefix.append(prefix[-1] + i)
		for i in range(1, len(arr)):
			idash = i - (i & -i)
			self.farr.append(prefix[i] - prefix[idash])

	def query(self, l, r):
		return self.prefixSum(r) - self.prefixSum(l - 1)

	def prefixSum(self, idx):
		s = 0
		while idx > 0:
			s += self.farr[idx]
			idx -= idx & -idx
		return s

	def update(self, idx, val):
		while idx < len(self.farr):
			self.farr[idx] += val
			idx += idx & -idx

class DSU:

	def __init__(self, n):
		self.parent = []
		self.size = []
		for i in range(n + 1):
			self.parent.append(i)
			self.size.append(1)

	def union(self, u, v):
		pu = self.findPar(u)
		pv = self.findPar(v)
		if pu == pv:
			return
		if self.size[pu] < self.size[pv]:
			self.parent[pu] = pv
			self.size[pv] += self.size[pu]
		else:
			self.parent[pv] = pu
			self.size[pu] += self.size[pv]

	def unionByRank(self, u, v):
		pu = self.findPar(u)
		pv = self.findPar(v)
		if pu == pv:
			return
		if self.rank[pu] < self.rank[pv]:
			self.parent[pu] = pv
		elif self.rank[pv] < self.rank[pu]:
			self.parent[pv] = pu
		else:
			self.parent[pu] = pv
			self.rank[pv] += 1

	def findPar(self, node):
		if self.parent[node] == node:
			return node
		self.parent[node] = self.findPar(self.parent[node])
		return self.parent[node]

class info:

	def __init__(self, _open=0, _close=0, _full=0):
		self.open = _open
		self.close = _close
		self.full = _full

class SGTree:

	def __init__(self, n):
		self.seg = [0 for _ in range(4 * n)]

	def build(self, ind, low, high, arr):
		if low == high:
			self.seg[ind] = arr[low]
			return
		mid = (low + high) // 2
		self.build(2 * ind + 1, low, mid, arr)
		self.build(2 * ind + 2, mid + 1, high, arr)
		self.seg[ind] = min(self.seg[2 * ind + 1], self.seg[2 * ind + 2])

	def query(self, ind, low, high, l, r):
		if r < low or l > high:
			return sys.maxsize
		if low <= l and r >= high:
			return self.seg[ind]
		mid = low + high >> 1
		left = self.query(2 * ind + 1, 0, mid, l, r)
		right = self.query(2 * ind + 2, mid + 1, high, l, r)
		return min(left, right)

	def update(self, ind, low, high, i, val):
		if low == high:
			self.seg = val
			return
		mid = low + high >> 1
		if i <= mid:
			self.update(2 * ind + 1, low, mid, i, val)
		else:
			self.update(2 * ind + 1, mid + 1, high, i, val)
		self.seg[ind] = min(self.seg[2 * ind + 1], self.seg[2 * ind + 2])

def isPalindrome(s):
	i = 0
	j = len(s) - 1
	while i < j:
		if s[i] != s[j]:
			return False
		i += 1
		j -= 1
	return True

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

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

def getStrs():
	return sys.stdin.readline().strip()

def StrList():
	list(sys.stdin.readline().strip())

def FloatList():
	lis = input().split()
	lis = list(map(float, lis))
	return lis

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n + 1):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p]:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1

def findPrimePair(n):
	isPrime = [0] * (n + 1)
	SieveOfEratosthenes(n, isPrime)
	for i in range(0, n):
		if isPrime[i] and isPrime[n - i]:
			print(i, n - i)
			return

def query(ind, low, high, l, r, seg):
	if r < low or l > high:
		return info()
	if low <= l and r >= high:
		return self.seg[ind]
	mid = low + high >> 1
	left = self.query(2 * ind + 1, 0, mid, l, r, seg)
	right = self.query(2 * ind + 2, mid + 1, high, l, r, seg)
	return merge(left, right)

def merge(left, right):
	ans = info()
	ans.full = left.full + right.full + min(left.open, right.close)
	ans.open = left.open + right.open + min(left.open, right.close)
	ans.close = left.close + right.close + min(left.open, right.close)
	return ans

def build(ind, low, high, s, seg):
	if low == high:
		seg[ind] = info(s[low] == '(', s[low] == ')', 0)
		return
	mid = (low + high) // 2
	build(2 * ind + 1, low, mid, s, seg)
	build(2 * ind + 2, mid + 1, high, s, seg)
	seg[ind] = merge(seg[2 * ind + 1], seg[2 * ind + 2])

def countN(lis):
	ans = 0
	cnt = 0
	for i in range(len(lis) - 1, -1, -1):
		if lis[i] == 0:
			cnt += 1
		else:
			ans += cnt
	return ans

class Pair:

	def __init__(self, x, y, gcd):
		self.x = x
		self.y = y
		self.gcd = gcd

def Euclidean(a, b):
	if b == 0:
		return Pair(1, 0, a)
	dash = Euclidean(b, a % b)
	return Pair(dash.y, dash.x - a // b * dash.y, dash.gcd)

def chineseRemainder(a1, n1, a2, n2):
	p = Euclidean(n1, n2)
	x = p.x
	gcd = p.gcd
	if (a1 - a2) % gcd:
		return -1
	k = (a1 - a2) // gcd
	a = a1 - n1 * (k * x % n2 // gcd)
	lcm = n1 * n2 // gcd
	if a < 0:
		a += lcm
	return a
mdd = 998244353

def ncr(n, k, md):
	mod = 998244353
	tab = [[0 for _ in range(k + 1)] for i in range(n + 1)]
	for i in range(1, len(tab)):
		tab[i][0] = 1
	for i in range(1, len(tab)):
		for j in range(1, min(i + 1, len(tab[0]))):
			if i == 1 and j == 1:
				tab[i][j] = 1
			else:
				tab[i][j] = (tab[i - 1][j] + tab[i - 1][j - 1]) % mod
	return tab

def repeat(i, j, arr):
	if i > j:
		return
	cnt1 = i
	cnt2 = j
	while cnt1 < cnt2:
		(arr[cnt1], arr[cnt2]) = (arr[cnt2], arr[cnt1])
		cnt1 += 1
		cnt2 -= 1
	if i - 1 >= 0:
		ele = arr[i - 1]
		if ele > 0:
			s = int(sqrt(ele - 1)) + 1
			first = s * s - ele
			repeat(first, i - 1, arr)
	return
spf = []

def makeSeive(n):
	for i in range(n + 1):
		spf.append(i)

def seive(n):
	s = int(sqrt(n + 1))
	for i in range(2, s + 1):
		if spf[i] == i:
			for j in range(i * i, n + 1, i):
				if spf[j] == j:
					spf[j] = i

def getFactorization(x):
	ret = set()
	while x != 1:
		ret.add(spf[x])
		x = x // spf[x]
	return ret

def zFunc(patt, txt):
	st = patt + '#' + txt
	zArray = [0 for _ in range(len(st))]
	l = 0
	r = 0
	for i in range(1, len(st)):
		if r >= i:
			zArray[i] = min(r - i + 1, zArray[i - l])
		while i + zArray[i] < len(st) and st[zArray[i]] == st[zArray[i] + i]:
			zArray[i] += 1
		if zArray[i] + i - 1 > r:
			l = i
			r = i + zArray[i] - 1
	return zArray.count(len(patt))

def kmp(txt, patt):
	newString = patt + '#' + txt
	freqCount = 0
	freqArray = [0 for _ in range(len(newString))]
	i = 1
	length = 0
	while i < len(newString):
		if newString[i] == newString[length]:
			length += 1
			freqArray[i] = length
			i += 1
		elif length > 0:
			length = freqArray[length - 1]
		else:
			freqArray[i] = 0
			i += 1
	for i in freqArray:
		if i == len(patt):
			freqCount += 1
	return freqCount

def getLPS(s):
	st = '@#' + '#'.join(s) + '#&'
	c = 0
	r = 0
	lps = [0] * len(st)
	for i in range(1, len(st) - 1):
		mirror = c - (i - c)
		if i < r and mirror >= 0:
			lps[i] = min(lps[mirror], r - i)
		while st[i + lps[i] + 1] == st[i - lps[i] - 1]:
			lps[i] += 1
		if i + lps[i] > r:
			r = i + lps[i]
			c = i
	return max(lps)
fact = [1 for _ in range(100002)]
mod = 10 ** 9 + 7

def getFact(n):
	for i in range(1, n + 1):
		fact[i] = fact[i - 1] * i % mod

def getInv(word):
	num = math.factorial(len(word))
	for v in Counter(word).values():
		num = num * pow(math.factorial(v), mod - 2, mod) % mod
	return int(num) % (10 ** 9 + 7)

def subarrayXor(arr, n, m):
	HashTable = defaultdict(bool)
	HashTable[0] = 1
	count = 0
	curSum = 0
	for i in arr:
		curSum ^= i
		if HashTable[curSum ^ m]:
			count += HashTable[curSum ^ m]
		HashTable[curSum] += 1
	return count

def get2dPrefixSum(matrix, mid=0):
	n = len(matrix)
	m = len(matrix[0])
	prefix = [[0 for _ in range(m + 1)] for i in range(n + 1)]
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			prefix[i][j] = prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1] + matrix[i - 1][j - 1]
	return prefix

def get2dPrefixSumCnt(matrix, mid=0):
	n = len(matrix)
	m = len(matrix[0])
	prefix = [[0 for _ in range(m + 1)] for i in range(n + 1)]
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			prefix[i][j] = prefix[i - 1][j] + prefix[i][j - 1] - prefix[i - 1][j - 1] + matrix[i - 1][j - 1]
	return prefix

def getSumRange(r1, c1, r2, c2, prefix):
	cnt = prefix[r2][c2] - prefix[r2][c1 - 1] - prefix[r1 - 1][c2] + prefix[r1 - 1][c1 - 1]
	return cnt

def getPrefix(arr):
	prefix = [0]
	for i in arr:
		prefix.append(prefix[-1] + i)
	return prefix

def getInv(arr):
	cnt = 0
	ans = []
	for i in arr:
		ind = bisect_right(ans, i)
		cnt += len(ans) - ind
		insort(ans, i)
	return cnt
M = 10 ** 5

def getFactors(x):
	temp = []
	k = 1
	while k * k <= x:
		if x % k == 0:
			temp.append(k)
			if k * k != x:
				temp.append(x // k)
		k += 1
	return temp

def grayCode(n):
	if not n:
		return [0]
	res = [0, 1]
	for i in range(2, n + 1):
		for j in range(len(res) - 1, -1, -1):
			res.append(res[j] | 1 << i - 1)
	return res

def threeSum(nums, target):
	ans = -1
	d = dict()
	for (i, j) in enumerate(nums):
		d[j] = i + 1
	nums.sort()
	for i in range(len(nums) - 2):
		low = i + 1
		high = len(nums) - 1
		while low < high:
			s = nums[i] + nums[low] + nums[high]
			if s == target:
				print(d[nums[low]], d[nums[high]], d[nums[i]])
				return
				low += 1
				high -= 1
			elif s < 0:
				low = low + 1
			else:
				high -= 1
	print('IMPOSSIBLE')
	return

def FuckCF():
	(n, k) = getInts()
	lis1 = IntList()
	lis2 = IntList()
	temp = [[lis1[i], lis2[i]] for i in range(n)]
	temp.sort(key=lambda x: (x[0] + x[1], x[0]))
	cnt = 0
	i = 0
	s = 0
	mx = 0
	while i < n:
		if temp[i][0] + temp[i][1] + s <= k:
			s += temp[i][0] + temp[i][1]
			mx = max(mx, temp[i][1])
			i += 1
		else:
			break
	mn = [0] * n
	for j in range(n - 1, -1, -1):
		if j == n - 1:
			mn[j] = temp[j][0]
		else:
			mn[j] = min(mn[j + 1], temp[j][0])
	ans = i
	if i < n:
		rem = k - s
		if mn[i] <= rem:
			ans += 1
		elif rem + mx >= temp[i][0] + temp[i][1]:
			ans += 1
	print(ans)
t = 1
t = int(input())
for i in range(t):
	FuckCF()


def cmp(a, b):
	if a[0] + a[1] == b[0] + b[1]:
		return a[0] < b[0]
	else:
		return a[0] + a[1] < b[0] + b[1]

def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = [[a[i], b[i]] for i in range(n)]
	m.sort(key=lambda x: (x[0] + x[1], x[0]))
	mx = 0
	sm = 0
	i = 0
	while i < n and m[i][0] + m[i][1] + sm <= k:
		sm += m[i][0] + m[i][1]
		mx = max(mx, m[i][1])
		i += 1
	mn = [0] * n
	for j in range(n - 1, -1, -1):
		if j == n - 1:
			mn[j] = m[j][0]
		else:
			mn[j] = min(mn[j + 1], m[j][0])
	ans = i
	if i < n:
		rem = k - sm
		if mn[i] <= rem:
			ans += 1
		elif rem + mx >= m[i][0] + m[i][1]:
			ans += 1
	print(ans)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = []
	for i in range(n):
		ans.append([a[i] + b[i], a[i]])
	ans.sort()
	res = 0
	i = 0
	last = -1
	while i < n:
		if ans[i][0] <= k:
			res += 1
			k -= ans[i][0]
		else:
			last = i
			break
		i += 1
	aagya = 0
	while i < n:
		if ans[i][1] <= k:
			k -= ans[i][1]
			res += 1
			aagya = 1
			break
		i += 1
	if aagya == 0 and last != -1:
		k -= ans[last][0]
		for j in range(last - 1, -1, -1):
			if k + ans[j][0] - ans[j][1] >= 0:
				res += 1
				break
	print(res)


def getSolution(n, k, a):
	mx = 0
	sum = 0
	i = 0
	while i < n:
		if a[i][0] + a[i][1] + sum >= k:
			break
		else:
			sum += a[i][0] + a[i][1]
			mx = max(mx, a[i][1])
			i += 1
	temp = [0] * n
	kk = n - 1
	while kk >= 0:
		if kk == n - 1:
			temp[kk] = a[kk][0]
		else:
			temp[kk] = temp[kk + 1] if temp[kk + 1] <= a[kk][0] else a[kk][0]
		kk -= 1
	ans = i
	if i < n:
		rem = k - sum
		if temp[i] <= rem:
			ans += 1
		elif rem + mx >= a[i][0] + a[i][1]:
			ans += 1
	return ans

def compare(a, b):
	if a[0] + a[1] == b[0] + b[1]:
		return a[0] < b[0]
	return a[0] + a[1] < b[0] + b[1]

def c_p_c():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		arr = [(a[i], b[i]) for i in range(n)]
		arr.sort(key=lambda x: (x[0] + x[1], x[0]))
		print(getSolution(n, k, arr))
c_p_c()


def solve():
	m = []
	for i in range(n):
		m.append([a[i], b[i]])
	m.sort(key=lambda x: x[0] + x[1])
	mx = 0
	sum = 0
	i = 0
	while i < n:
		if m[i][0] + m[i][1] + sum <= k:
			sum += m[i][0] + m[i][1]
			mx = max(mx, m[i][1])
			i += 1
		else:
			break
	ans = i
	if i < n:
		rem = k - sum
		mn = float('inf')
		for j in range(i, n):
			mn = min(mn, m[j][0])
		if mn <= rem:
			ans += 1
		elif rem + mx >= m[i][0] + m[i][1]:
			ans += 1
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve())


def solve_case():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	m = [[a[i], b[i]] for i in range(n)]

	def key_func(x):
		return (x[0] + x[1], x[0])
	m.sort(key=key_func)
	max_val = 0
	sum_val = 0
	index = 0
	while index < n:
		if m[index][0] + m[index][1] + sum_val <= k:
			sum_val += m[index][0] + m[index][1]
			max_val = max(max_val, m[index][1])
			index += 1
		else:
			break
	min_vals = [0] * n
	for i in range(n - 1, -1, -1):
		if i == n - 1:
			min_vals[i] = m[i][0]
		else:
			min_vals[i] = min(min_vals[i + 1], m[i][0])
	ans = index
	if index < n:
		rem = k - sum_val
		if min_vals[index] <= rem:
			ans += 1
		elif rem + max_val >= m[index][0] + m[index][1]:
			ans += 1
	print(ans)
t = int(input())
for case in range(t):
	solve_case()


def compare(a, b):
	if a[0] + a[1] == b[0] + b[1]:
		return a[0] < b[0]
	else:
		return a[0] + a[1] < b[0] + b[1]

def solve():
	(n, k) = map(int, input().split())
	first_list = list(map(int, input().split()))
	second_list = list(map(int, input().split()))
	list_of_lists = [[first_list[i], second_list[i]] for i in range(n)]
	list_of_lists.sort(key=lambda x: (x[0] + x[1], x[0]))
	(mx, sm, i) = (0, 0, 0)
	while i < n:
		if list_of_lists[i][0] + list_of_lists[i][1] + sm <= k:
			sm += list_of_lists[i][0] + list_of_lists[i][1]
			mx = max(mx, list_of_lists[i][1])
			i += 1
		else:
			break
	mn = [0] * n
	for j in range(n - 1, -1, -1):
		if j == n - 1:
			mn[j] = list_of_lists[j][0]
		else:
			mn[j] = min(mn[j + 1], list_of_lists[j][0])
	ans = i
	if i < n:
		rem = k - sm
		if mn[i] <= rem:
			ans += 1
		elif rem + mx >= list_of_lists[i][0] + list_of_lists[i][1]:
			ans += 1
	print(ans)
t = int(input())
for _ in range(t):
	solve()


import sys
import math
import heapq

def cmp(x, y):
	if x[0] + x[1] == y[0] + y[1]:
		return x[0] < y[0]
	else:
		return x[0] + x[1] < y[0] + y[1]

def solve():
	(number, kon) = map(int, input().split())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	moon = []
	for i in range(number):
		moon.append([x[i], y[i]])
	moon.sort(key=lambda h: (h[0] + h[1], h[0]))
	mxxxx = 0
	sour = 0
	i = 0
	while i < number and moon[i][0] + moon[i][1] + sour <= kon:
		sour += moon[i][0] + moon[i][1]
		mxxxx = max(mxxxx, moon[i][1])
		i += 1
	mnnnn = [0] * number
	for j in range(number - 1, -1, -1):
		if j == number - 1:
			mnnnn[j] = moon[j][0]
		else:
			mnnnn[j] = min(mnnnn[j + 1], moon[j][0])
	store = i
	if i < number:
		rem = kon - sour
		if mnnnn[i] <= rem:
			store += 1
		elif rem + mxxxx >= moon[i][0] + moon[i][1]:
			store += 1
	print(store)
test = int(input())
for i in range(test):
	solve()


for _ in range(int(input())):
	(n, t) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [[a[i], b[i], a[i] + b[i]] for i in range(len(a))]
	c.sort(key=lambda x: x[2])
	i = 0
	aux = []
	while i < len(c) and t >= c[i][2]:
		t -= c[i][2]
		aux.append(c[i])
		i += 1
	aux.sort(key=lambda x: x[1])
	j = len(aux) - 1
	ans = i
	while i < len(c):
		if j >= 0:
			if aux[j][0] + c[i][2] <= aux[j][2] + c[i][0]:
				if t - (c[i][2] - aux[j][1]) >= 0:
					ans += 1
					t -= c[i][2] - aux[j][1]
					break
				elif t >= c[i][0]:
					ans += 1
					break
			elif t >= c[i][0]:
				ans += 1
				break
		elif t >= c[i][0]:
			ans += 1
			break
		i += 1
	print(ans)


from collections import defaultdict
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	tot = [[a[i] + b[i], a[i]] for i in range(n)]
	s = set()
	tot.sort()
	ans = 0
	fg = False
	for i in range(n):
		if tot[i][0] > k:
			fg = True
			break
		ans += 1
		k -= tot[i][0]
		s.add(tot[i][0] - tot[i][1])
	if k > 0 and fg:
		mx = max(s) if len(s) else 0
		for j in range(i, n):
			if tot[j][1] <= k or tot[i][0] - k <= mx:
				ans += 1
				break
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	problems = list(map(int, input().split()))
	breaks = list(map(int, input().split()))
	mixed = sorted(zip(problems, breaks), key=lambda x: (x[0] + x[1], x[0]))
	maxa = 0
	suma = 0
	i = 0
	while i < n and suma + mixed[i][0] + mixed[i][1] <= k:
		suma += mixed[i][0] + mixed[i][1]
		maxa = max(maxa, mixed[i][1])
		i += 1
	mina = [0] * n
	for j in range(n - 1, -1, -1):
		if j == n - 1:
			mina[j] = mixed[j][0]
		else:
			mina[j] = min(mina[j + 1], mixed[j][0])
	questions = i
	if i < n:
		remains = k - suma
		if mina[i] <= remains:
			questions += 1
		elif remains + maxa >= mixed[i][0] + mixed[i][1]:
			questions += 1
	print(questions)


from bisect import bisect
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	arr = []
	pref = [0]
	for i in range(n):
		arr.append((a[i] + b[i], a[i]))
	arr.sort(key=lambda x: (x[0], x[1]))
	pref = [0]
	idx = 0
	ans = 0
	anstmp = 0
	for i in range(len(arr)):
		pref.append(pref[-1] + arr[i][0])
	for i in range(n):
		lft = k - arr[i][1]
		if lft >= 0:
			ans = max(ans, 1)
		idx = bisect(pref, lft) - 1
		if idx - 1 >= i:
			idx = bisect(pref, lft + arr[i][0]) - 1
			idx -= 1
			ans = max(ans, idx + 1)
		else:
			ans = max(ans, idx + 1)
	for i in range(len(arr)):
		if k - arr[i][0] < 0:
			idx = i
			break
		else:
			k -= arr[i][0]
			anstmp += 1
	ans = max(ans, anstmp)
	print(ans)


from sys import stdin, stdout
input = stdin.readline
r_int = lambda : int(input())
m_int = lambda : map(int, input().split())
l_int = lambda : list(map(int, input().split()))

def solve():
	(n, k) = m_int()
	a = l_int()
	b = l_int()
	l = [(x + y, x, y) for (x, y) in zip(a, b)]
	l.sort()
	acc = 0
	n_ex = 0
	while n_ex < n and acc + l[n_ex][0] <= k:
		acc += l[n_ex][0]
		n_ex += 1
	if n_ex == n:
		print(n)
		return
	if acc + min((l[i][1] for i in range(n_ex, n))) <= k:
		print(n_ex + 1)
		return
	if n_ex == 0:
		print(0)
		return
	if acc + l[n_ex][0] - max((l[i][2] for i in range(n_ex))) <= k:
		print(n_ex + 1)
	else:
		print(n_ex)

def main():
	n_cases = r_int()
	for _ in range(n_cases):
		solve()
main()


from sys import stdin
input = stdin.readline

def solve(N, K, A, B):
	problem = sorted([(a + b, b, i) for (i, (a, b)) in enumerate(zip(A, B))])
	seen = set()
	answer = 0
	count = 0
	maxwait = 0
	while answer < N:
		if count + problem[answer][0] <= K:
			count += problem[answer][0]
			maxwait = max(maxwait, problem[answer][1])
			seen.add(problem[answer][2])
			answer += 1
		else:
			break
	for i in range(N):
		if i not in seen and (count + A[i] <= K or count + A[i] + B[i] - maxwait <= K):
			answer += 1
			break
	return answer
T = int(input().strip())
for problem in range(1, T + 1):
	(N, K) = [int(x) for x in input().strip().split()]
	A = [int(x) for x in input().strip().split()]
	B = [int(x) for x in input().strip().split()]
	print(solve(N, K, A, B))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	arr = [(A[x] + B[x], A[x]) for x in range(n)]
	arr.sort()
	ans = 0
	pre = [0] * n
	for i in range(n):
		pre[i] = arr[i][0] + (pre[i - 1] if i > 0 else 0)
		if pre[i] <= k:
			ans = i + 1
		if arr[i][1] <= k:
			ans = max(ans, 1)
	for i in range(n):
		t = k - arr[i][1]
		(l, h) = (i + 1, n - 1)
		left = False
		if i + 1 == n or pre[i + 1] - arr[i][0] > t:
			(l, h) = (0, i - 1)
			left = True
		while l <= h:
			mid = l + h >> 1
			if left:
				if pre[mid] <= t:
					ans = max(ans, mid + 2)
					l = mid + 1
				else:
					h = mid - 1
			elif pre[mid] - arr[i][0] <= t:
				ans = max(ans, mid + 1)
				l = mid + 1
			else:
				h = mid - 1
	print(ans)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
	for i in range(n):
		c.append((a[i] + b[i], a[i], b[i]))
	c.sort()
	ans = 0
	pre = 0
	from math import inf
	maxf = 0
	for i in range(n):
		if pre + c[i][0] < k:
			pre += c[i][0]
			maxf = max(maxf, c[i][2])
			ans = int(i + 1)
		else:
			temp = max(int(maxf), c[i][2])
			if pre + c[i][0] - temp <= k:
				ans += 1
				break
	print(ans)