There are N sweets in the store. The cost of the i^{th} sweet is A_{i} rupees. Chef is a regular customer, so after buying the i^{th} sweet, he gets a cashback of B_{i} rupees.

Chef has R rupees. He is fond of all the sweets, so he wants you to calculate the maximum number of sweets he can buy. Note that he can buy the same type of sweet multiple times, as long as he has the money to do so.

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

- The first line of input will contain T, 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 R — the number of sweets in the shop and the amount of money Chef has.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N}.
- The third line of each test case contains N space-separated integers B_{1}, B_{2}, \ldots, B_{N}.

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

For each query, print on a new line the maximum number of sweets Chef can buy.

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

$1 ≤T ≤2 \cdot 10^{5}$
$1 ≤N ≤2 \cdot 10^{5}$
$1 ≤B_{i} < A_{i} ≤10^{9}$
$1 ≤R ≤ 10^{9}$
- It is guaranteed that the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$

----- Sample Input 1 ------ 
3
3 3
2 3 4
1 1 1
2 4
5 4
1 2
4 10
4 4 5 5
1 2 4 2
----- Sample Output 1 ------ 
2
1
7

----- explanation 1 ------ 
Test case $1$: Chef buys the first sweet, which costs $2$ rupees and has a cashback of $1$ rupee. He now has $3 - 2 + 1 = 2$ rupees remaining. He once again buys the first sweet, which leaves him with $1$ rupee, at which point no more sweets can be bought.

Test case $2$: Chef buys the second sweet once.

Difficulty: MEDIUM_HARD
Tags: Mathematics

Starter code:

Solutions:
import math

def check(pv, n, r, count):
	for i in range(n):
		if r >= pv[i][0]:
			budget = r - pv[i][0]
			to_buy = 0
			if budget > 0:
				to_buy = math.floor(budget / (pv[i][0] - pv[i][1]))
			r = r - (to_buy + 1) * (pv[i][0] - pv[i][1])
			count = count + to_buy + 1
			return [r, count]
	return [r, count]

def get_price(item):
	return item[0]

def get_diff(item):
	return item[0] - item[1]
t = int(input())
for i in range(t):
	(n, r) = map(int, input().split())
	A = list((int(e) for e in input().split()))
	B = list((int(e) for e in input().split()))
	pv_list = list(((A[i], B[i]) for i in range(n)))
	sort_by_p_list = sorted(pv_list, key=get_price)
	sorted_pv_list = sorted(sort_by_p_list, key=get_diff)
	count = 0
	start = check(sorted_pv_list, n, r, count)
	while (r >= min(A)) & (start[1] > count):
		r = start[0]
		count = start[1]
		start = check(sorted_pv_list, n, r, count)
	print(count)


t = int(input())
for i in range(t):
	(n, r) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = 0
	l = []
	for j in range(n):
		l.append(a[j] - b[j])
	while r >= min(a):
		p = []
		for k in range(len(a)):
			if r >= a[k]:
				p.append(l[k])
		x = l.index(min(p))
		count = (r - a[x]) // l[x] + 1
		r -= count * l[x]
		c += count
		del a[x], b[x], l[x]
		if a == []:
			break
	print(c)


t = int(input())
while t:
	t -= 1
	(n, r) = map(int, input().split())
	A = list(map(int, input().split()))
	C = list(map(int, input().split()))
	ans = 0
	for i in range(len(A)):
		C[i] = [A[i], C[i] - A[i]]
	C = sorted(C, key=lambda x: [-1 * x[1], x[0]])
	while len(C) > 0:
		temp = C.pop(0)
		A = temp[0]
		B = temp[1]
		flag = False
		if r > 2 * A:
			r -= A
			flag = True
			ans += r // abs(B)
			r = r % abs(B)
		if flag:
			r += A
		while r >= A:
			r = r + B
			ans += 1
	print(ans)


import math
for _ in range(int(input())):
	(sweet_type, money) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	sweet = 0
	A = sorted(list(zip(A, B)))
	stack = [A[0]]
	for i in A:
		if i[0] > money:
			break
		if stack[-1][0] == i[0] and i[1] - i[0] > stack[-1][1] - stack[-1][0]:
			stack[-1] = i
		elif i[1] - i[0] > stack[-1][1] - stack[-1][0]:
			stack.append(i)
	while stack and money >= stack[-1][0]:
		sweet_prev = sweet
		sweet += math.ceil((money - stack[-1][0] + 1) / (stack[-1][0] - stack[-1][1]))
		money -= (sweet - sweet_prev) * (stack[-1][0] - stack[-1][1])
		stack.pop()
	print(sweet)


t = int(input())
for i in range(t):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = list((a[x] - b[x] for x in range(n)))
	l = [[x, y] for (x, y) in zip(l, a)]
	l.sort()
	s = 0
	for i in l:
		if i[1] <= r:
			p = (r - i[1]) // i[0] + 1
			s += p
			r = r - p * i[0]
		if r <= 0:
			break
	print(s)


for i in range(int(input())):
	(l, money) = input().split()
	l = int(l)
	money = int(money)
	A = input().split()
	B = input().split()
	C = []
	for i in range(l):
		A[i] = int(A[i])
		B[i] = int(B[i])
		C.append((A[i], B[i], A[i] - B[i]))
	C = sorted(C, key=lambda x: x[2])
	res = 0
	for i in range(l):
		if money >= C[i][0]:
			q = (money - C[i][0]) // C[i][2]
			money -= q * C[i][2]
			res += q
		while money >= C[i][0]:
			res += 1
			money -= C[i][2]
	print(res)


from heapq import *
t = int(input())
for _ in range(t):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	h = []
	for i in range(n):
		heappush(h, (a[i] - b[i], a[i]))
	cnt = 0
	while r > 0:
		if not h:
			break
		ele = heappop(h)
		if r < ele[1]:
			continue
		else:
			c = (r - ele[1]) // ele[0] + 1
			r -= ele[0] * c
			cnt += c
	print(cnt)


for _ in range(int(input())):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	d = [[a[i], b[i], a[i] - b[i]] for i in range(n)]
	d.sort(key=lambda x: x[0])
	d.sort(key=lambda x: x[2])
	for elem in d:
		if elem[0] <= r:
			ans += int((r - elem[0]) / elem[2])
			r -= int((r - elem[0]) // elem[2] * elem[2])
			if r >= elem[0]:
				r -= elem[2]
				ans += 1
	print(ans)


import math

def cands(t, c, b):
	return int((t - c) / (c - b)) + 1
t = int(input())
for _ in range(t):
	(n, r) = 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()
	candy = 0
	for j in range(n):
		if c[j][1] <= r:
			cbuy = cands(r, c[j][1], c[j][2])
			r -= cbuy * c[j][0]
			candy += cbuy
	print(candy)


for _ in range(int(input())):
	(N, R) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	C = [[a - b, a, b] for (a, b) in zip(A, B)]
	C.sort()
	x = 0
	i = 0
	while i < len(C):
		if R >= C[i][1]:
			x += (R - C[i][1]) // C[i][0] + 1
			R -= ((R - C[i][1]) // C[i][0] + 1) * C[i][0]
		i = i + 1
		if R == 0:
			break
	print(x)


for _ in range(int(input())):
	(n, bal) = map(int, input().split())
	a = list(map(lambda a, b: [int(a) - int(b), int(a)], input().split(), input().split()))
	a.sort()
	c = 0
	ans = 0
	while c < n:
		while bal >= a[c][1]:
			times = bal // a[c][1]
			ans += times
			bal -= a[c][0] * times
		c += 1
	print(ans)


t = int(input())
for T in range(t):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 0
	count = []
	for i in range(n):
		temp = []
		temp.append(a[i] - b[i])
		temp.append(a[i])
		temp.append(b[i])
		count.append(temp)
	count.sort()
	for i in range(n):
		if r >= count[i][1]:
			ans += (r - count[i][1]) // count[i][0] + 1
			r -= ((r - count[i][1]) // count[i][0] + 1) * count[i][0]
	print(ans)


import sys
from sys import stdin, stdout
for _ in range(int(input())):
	r = int(sys.stdin.readline().split()[1])
	c = filter(lambda x: x[1] <= r, sorted([(ai - bi, ai) for (ai, bi) in zip(map(int, sys.stdin.readline().split()), map(int, sys.stdin.readline().split()))]))
	ans = 0
	while (c1 := next(c, None)) is not None:
		t = (r - c1[1]) // c1[0] + 1
		ans += t
		r -= t * c1[0]
		c = filter(lambda x: x[1] <= r, c)
	print(ans)


import sys
from sys import stdin, stdout
for _ in range(int(input())):
	(n, r) = map(int, sys.stdin.readline().split())
	a = [int(x) for x in sys.stdin.readline().split()]
	b = [int(x) for x in sys.stdin.readline().split()]
	c = []
	for i in range(n):
		c.append((a[i] - b[i], a[i]))
	c = sorted(c)
	mn = min(a)
	ans = 0
	i = 0
	while r >= mn:
		if r >= c[i][1]:
			t = (r - c[i][1]) // c[i][0] + 1
			ans += t
			r -= t * c[i][0]
		i += 1
	print(ans)


for _ in range(int(input())):
	(n, r) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = []
	for i in range(n):
		c.append((a[i] - b[i], a[i]))
	c = sorted(c)
	mn = min(a)
	ans = 0
	i = 0
	while r >= mn:
		if r >= c[i][1]:
			t = (r - c[i][1]) // c[i][0] + 1
			ans += t
			r -= t * c[i][0]
		i += 1
	print(ans)


for _ in range(int(input())):
	r = int(input().split()[1])
	a = [int(x) for x in input().split()]
	mn = min(a)
	c = sorted([(ai, ai - bi) for (ai, bi) in zip(a, map(int, input().split())) if ai <= r], key=lambda x: x[1])
	ans = 0
	i = 0
	while r >= mn:
		if r >= c[i][0]:
			t = (r - c[i][0]) // c[i][1] + 1
			ans += t
			r -= t * c[i][1]
		i += 1
	print(ans)


for _ in range(int(input())):
	r = int(input().split()[1])
	a = [int(x) for x in input().split()]
	mn = min(a)
	c = iter(sorted([(ai, ai - bi) for (ai, bi) in zip(a, map(int, input().split())) if ai <= r], key=lambda x: x[1]))
	ans = 0
	while r >= mn and (c1 := next(c, False)):
		t = (r - c1[0]) // c1[1] + 1
		ans += t
		r -= t * c1[1]
		c = filter(lambda x: x[0] <= r, c)
	print(ans)


for _ in range(int(input())):
	r = int(input().split()[1])
	c = filter(lambda x: x[0] <= r, sorted([(ai, ai - bi) for (ai, bi) in zip(map(int, input().split()), map(int, input().split()))], key=lambda x: x[1]))
	ans = 0
	while (c1 := next(c, False)):
		t = (r - c1[0]) // c1[1] + 1
		ans += t
		r -= t * c1[1]
		c = filter(lambda x: x[0] <= r, c)
	print(ans)


for _ in range(int(input())):
	(n, r) = map(int, input().split())
	a = map(int, input().split())
	b = map(int, input().split())
	c = sorted([(ai, ai - bi) for (ai, bi) in zip(a, b)], key=lambda x: x[1])
	ans = 0
	c = filter(lambda x: x[0] <= r, c)
	while (c1 := next(c, None)) is not None:
		t = (r - c1[0]) // c1[1] + 1
		ans += t
		r -= t * c1[1]
		c = filter(lambda x: x[0] <= r, c)
	print(ans)


for _ in range(int(input())):
	(n, r) = map(int, input().split())
	a = map(int, input().split())
	b = map(int, input().split())
	c = sorted([(ai, ai - bi) for (ai, bi) in zip(a, b)], key=lambda x: x[1])
	ans = 0
	c = list(filter(lambda x: x[0] <= r, c))
	while bool(c):
		t = (r - c[0][0]) // c[0][1] + 1
		ans += t
		r -= t * c[0][1]
		c = list(filter(lambda x: x[0] <= r, c))
	print(ans)


def sortSecond(val):
	return val[0] - val[1]
t = int(input())
for i in range(t):
	ar = list(map(int, input().split()))
	n = ar[0]
	amount = ar[1]
	arr = list(map(int, input().split()))
	dis = list(map(int, input().split()))
	pair = [[arr[i], dis[i]] for i in range(n)]
	pair.sort(key=sortSecond)
	count = 0
	for i in range(n):
		while pair[i][0] <= amount:
			x = amount // pair[i][0]
			count += x
			amount -= x * (pair[i][0] - pair[i][1])
	print(count)


for i in range(int(input())):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = [[a[i] - b[i], a[i]] for i in range(n)]
	l.sort()
	t = 0
	for i in range(n):
		while r >= l[i][1]:
			x = r // l[i][1]
			t += x
			r -= x * l[i][0]
	print(t)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	x = list(map(int, input().split()))
	y = list(map(int, input().split()))
	l = [[x[i] - y[i], x[i]] for i in range(n)]
	l.sort()
	items = 0
	for i in range(n):
		while m >= l[i][1]:
			z = m // l[i][1]
			items += z
			m -= z * l[i][0]
	print(items)


t = int(input())
for _ in range(t):
	(n, r) = map(int, input().split())
	la = list(map(int, input().split()))
	lb = list(map(int, input().split()))
	lc = sorted([(la[i] - lb[i], la[i], lb[i]) for i in range(n)])
	ans = 0
	while len(lc) > 0:
		while r >= lc[0][1]:
			(d, a, b) = (lc[0][0], lc[0][1], lc[0][2])
			ans += r // a
			r -= r // a * d
		lc.pop(0)
	print(ans)


def Test(n, r, a, b):
	arr = [[a[i] - b[i], a[i]] for i in range(n)]
	count = 0
	arr.sort()
	for i in range(n):
		if arr[i][1] > r:
			continue
		res = int((r - (arr[i][1] - arr[i][0])) / arr[i][0])
		count += res
		r -= res * arr[i][0]
	return count
for _ in range(int(input())):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(Test(n, r, a, b))


T = int(input())
for i in range(T):
	(N, R) = map(int, input().split())
	A = [int(a) for a in input().split()]
	B = [int(b) for b in input().split()]
	C = sorted([(A[i] - B[i], A[i]) for i in range(N)])
	n = 0
	i = 0
	while i < N and R > 0:
		if C[i][1] > R:
			i += 1
		else:
			n += (R - C[i][1]) // C[i][0] + 1
			R -= ((R - C[i][1]) // C[i][0] + 1) * C[i][0]
			i += 1
	print(n)


for i in range(int(input())):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	opr = [[a[i] - b[i], [a[i], b[i]]] for i in range(n)]
	opr.sort()
	res = 0
	for i in range(n):
		while r >= opr[i][1][0]:
			temp = r // opr[i][1][0]
			res += temp
			r -= temp * opr[i][1][0]
			r += temp * opr[i][1][1]
	print(res)


tests = int(input())
for i in range(tests):
	(sweets, money) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	options = [[a[i] - b[i], [a[i], b[i]]] for i in range(sweets)]
	options.sort()
	result = 0
	for i in range(sweets):
		while money >= options[i][1][0]:
			temp = money // options[i][1][0]
			result += temp
			money -= temp * options[i][1][0]
			money += temp * options[i][1][1]
	print(result)


for _ in range(int(input())):
	(N, R) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	cost = [[A[i] - B[i], A[i]] for i in range(N)]
	cnt1 = 0
	cost.sort()
	for i in range(N):
		if cost[i][1] > R:
			continue
		nos = int((R - (cost[i][1] - cost[i][0])) / cost[i][0])
		cnt1 += nos
		R -= nos * cost[i][0]
	print(cnt1)


t = int(input())
for testcase in range(t):
	(n, r) = map(int, input().split())
	cost = [(int(a), int(b), int(a) - int(b)) for (a, b) in zip(input().split(), input().split())]
	cost.sort(key=lambda x: x[2])
	ans = 0
	for i in range(n):
		if r >= cost[i][0]:
			sweet_count = int((r - cost[i][1]) / cost[i][2])
			r -= sweet_count * cost[i][2]
			ans += sweet_count
	print(ans)


t = int(input())
for _ in range(t):
	(n, r) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	v = [[a[i] - b[i], [a[i], b[i]]] for i in range(n)]
	v.sort()
	res = 0
	for i in range(n):
		while r >= v[i][1][0]:
			temp = r // v[i][1][0]
			res += temp
			r -= temp * v[i][1][0]
			r += temp * v[i][1][1]
	print(res)


t = int(input())
for _ in range(t):
	(n, rem) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l = [(l1[i], l1[i] - l2[i]) for i in range(n)]
	l.sort(key=lambda val: val[1])
	ans = 0
	for i in l:
		if rem >= i[0]:
			cnt = (rem - i[0]) // i[1]
			rem -= cnt * i[1]
			if rem >= i[0]:
				rem -= i[0]
				rem += i[0] - i[1]
				cnt += 1
			ans += cnt
	print(ans)


from functools import cmp_to_key
import math
from pydoc import doc

def run(debug=True):
	for _ in range(int(input())):
		(n, r) = list(map(int, input().split()))
		cost = list(map(int, input().split()))
		discount = list(map(int, input().split()))
		discountedCost = []
		for i in range(n):
			discountedCost.append([cost[i] - discount[i], i])
		discountedCost.sort(key=lambda x: x[0])
		ans = 0
		for i in range(n):
			[currDiscountedCost, ind] = discountedCost[i]
			currCost = cost[ind]
			currDiscount = discount[ind]
			if currCost > r:
				continue
			bought = (r - currDiscount) // currDiscountedCost
			ans += bought
			r -= bought * currDiscountedCost
		print(ans)
while True:
	try:
		run(False)
	except:
		break


t = int(input())
for _ in range(t):
	(n, r) = map(int, input().split())
	p = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	l = []
	for i in range(n):
		l.append([p[i] - c[i], p[i]])
	l.sort()
	i = 0
	ans = 0
	while i < n:
		while r >= l[i][1]:
			sc = (r - (l[i][1] - l[i][0])) // l[i][0]
			ans += sc
			r -= sc * l[i][0]
		i += 1
	print(ans)


def lisin():
	a = list(map(int, input().split()))
	return a
for tastcas in range(int(input())):
	(n, r) = lisin()
	a = lisin()
	b = lisin()
	dic = []
	ans = 0
	rem = r
	mincost = min(a)
	for i in range(n):
		dic.append((a[i] - b[i], a[i]))
	dic.sort()
	(effcost, buycost) = dic[0]
	if rem >= buycost:
		ans += (rem - buycost) // effcost
		rem -= ans * effcost
	if rem >= buycost:
		ans += 1
		rem -= effcost
	for i in range(1, n):
		(effcost, buycost) = dic[i]
		while rem >= buycost:
			ans += 1
			rem -= effcost
		if rem < mincost:
			break
	print(ans)


t = int(input())
for i in range(t):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = []
	for j in range(n):
		x = a[j] - b[j]
		l.append([x, a[j], b[j]])
	l.sort()
	s = 0
	for z in range(n):
		while r >= l[z][1]:
			c = (r - l[z][2]) // l[z][0]
			s += c
			r -= c * l[z][1]
			r += c * l[z][2]
	print(s)


T = int(input())
for _ in range(T):
	(n, r) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	arr = []
	for i in range(n):
		x = A[i] - B[i]
		arr.append([x, A[i], B[i]])
	arr.sort()
	total_sweets = 0
	for i in range(n):
		while r >= arr[i][1]:
			temp = (r - arr[i][2]) // arr[i][0]
			total_sweets += temp
			r -= temp * arr[i][1]
			r += temp * arr[i][2]
	print(total_sweets)


import math
for _ in range(int(input())):
	(n, r) = map(int, input().split())
	cost = list(map(int, input().split()))
	cb = list(map(int, input().split()))
	count = 0
	new = []
	for i in range(n):
		diff = cost[i] - cb[i]
		new.append([cost[i], cb[i], diff])
	new.sort(key=lambda x: x[2])
	for i in range(n):
		if new[i][0] <= r:
			var1 = (r - new[i][1]) // new[i][2]
			r = r - var1 * new[i][2]
			count += var1
	print(count)


for i in range(int(input())):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append([a[i], b[i], a[i] - b[i]])
	l.sort(key=lambda x: x[2])
	count = 0
	for i in range(n):
		if l[i][0] <= r:
			x = (r - l[i][0]) // l[i][2] + 1
			r -= x * l[i][2]
			count += x
	print(count)


import math
t = int(input())
for _ in range(t):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	arr = []
	for i in range(n):
		arr.append((a[i] - b[i], a[i]))
	arr.sort()
	ans = 0
	for i in range(n):
		ns = max(math.ceil((r - arr[i][1] + 1) / arr[i][0]), 0)
		ans += ns
		r -= ns * arr[i][0]
	print(ans)


import sys
sys.setrecursionlimit(10 ** 5)

def pro(arr, b, r):
	n = len(arr)
	for i in range(n):
		arr[i] = (arr[i], b[i])
	x = sorted(arr, key=lambda x: x[0] - x[1])
	print(check(x, r))

def check(arr, k):
	c = 0
	for i in range(len(arr)):
		if k - arr[i][0] >= 0:
			ans = (k - arr[i][1]) // (arr[i][0] - arr[i][1])
			c += ans
			k = k - ans * (arr[i][0] - arr[i][1])
	return c
t = int(input())
for i in range(t):
	(n, r) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	b = list(map(int, input().split()))
	pro(arr, b, r)


t = int(input())
while t != 0:
	t -= 1
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	e = []
	for i in range(0, n):
		e.append((a[i] - b[i], a[i]))
	e.sort()
	ans = 0
	for i in range(len(e)):
		eff = e[i][0]
		actual = e[i][1]
		if actual <= r:
			buy_max = (r - actual + eff) // eff
			ans += buy_max
			r -= buy_max * eff
	print(ans)


from sys import stdin, stdout
import math
from collections import Counter
import functools
import time

def tr():
	return range(int(line()))

def sm():
	return map(int, line().split())

def ln():
	return list(sm())

def nl():
	return int(line())

def ssm():
	return map(str, line().split())

def line():
	return stdin.readline().rstrip()

def b(x):
	return bin(x).replace('0b', '')

def o(x):
	if type(x) != type(''):
		x = str(x)
	stdout.write(x + '\n')

def osp(x):
	if type(x) != type(''):
		x = str(x)
	stdout.write(x + ' ')

def ol(x):
	stdout.write(' '.join(map(str, x)) + '\n')

def main():
	for _ in tr():
		(n, r) = sm()
		a = ln()
		b = ln()
		order = []
		for i in range(n):
			order.append((a[i] - b[i], a[i]))
		order.sort()
		count = 0
		for i in range(n):
			if order[i][1] <= r:
				buy_max = (r - order[i][1] + order[i][0]) // order[i][0]
				count += buy_max
				r -= buy_max * order[i][0]
		print(count)
main()


t = int(input())
for i in range(t):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append([a[i] - b[i], a[i]])
	l = sorted(l)
	ans = 0
	for i in range(n):
		originalcost = l[i][1]
		effectivecost = l[i][0]
		cashback = originalcost - effectivecost
		if r < originalcost:
			continue
		ans = ans + 1
		r = r - originalcost
		ans = ans + r // effectivecost
		r = r % effectivecost
		r = r + cashback
	print(ans)


R = lambda : input()
I = lambda : int(R())
M = lambda : map(int, R().split())
RS = lambda : map(str, R().split(' '))
L = lambda : list(M())
Nsum = lambda n: n * (n + 1) // 2
Det = lambda a, b, c: (-b + (b * b - 4 * a * c) ** 0.5) / 2
iBit = lambda n, i: n >> i & 1
Div2 = lambda x: x & ~(x - 1)
pow2 = lambda x: log(Div2(x), 2)
lcm = lambda x, y: x * y // gcd(x, y)
mode = lambda counter: counter.most_common(1)[0]

def Mapp(arr):
	d = {}
	for i in arr:
		try:
			d[i] += 1
		except:
			d[i] = 1
	return d

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

def isPrime(n):
	if n < 3:
		return n == 2
	for i in range(3, n, 2):
		if n % i == 0:
			return False
	return True

def Pow(a, b, mod):
	res = 1
	while b:
		if b & 1:
			res = res * a % mod
		a *= a
		b >>= 1
	return res

def nCr(n, r):
	x = y = 1
	if n - r < r:
		r = n - r
	while r:
		x *= n
		y *= r
		g = gcd(x, y)
		x //= g
		y //= g
		n -= 1
		r -= 1
	return x

def Countarr(li, n):
	arr = []
	i = 0
	mx = 0
	c = li[0]
	cnt = 0
	while i < n:
		if c == li[i]:
			cnt += 1
		else:
			mx = max(mx, cnt)
			arr.append(cnt)
			cnt = 1
			c = li[i]
		i += 1
	mx = max(mx, cnt)
	arr.append(cnt)
	return (C(arr), mx)
for _ in range(I()):
	(n, r) = M()
	i = 0
	cnt = 0
	w = L()
	p = L()
	arr = [[w[i], p[i]] for i in range(n)]
	arr.sort(key=lambda x: x[0] - x[1])
	ans = 0
	for i in arr:
		if i[0] <= r:
			while r >= i[0]:
				c = r // i[0]
				r = r % i[0] + i[1] * c
				ans += c
	print(ans)


t = int(input())
for _ in range(t):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = sorted([(a[i] - b[i], a[i]) for i in range(n)])
	count = 0
	for i in range(n):
		(eff, org) = c[i]
		if r < org:
			continue
		buy = (r - org) // eff + 1
		count += buy
		r -= eff * buy
	print(count)


import sys
import os
import math
from collections import *
import bisect
from heapq import *
from itertools import permutations
if os.path.exists('input.txt') and os.path.exists('output.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
input = sys.stdin.readline

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

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

def lis():
	return list(inp())
mod = 998244353

def prim(n):
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True
ma = 2 * (10 ** 5 + 1)

def update(ind, val, n):
	while ind <= n:
		fenwick[ind] += val
		ind += ind & -ind

def qsum(ind):
	ans = 0
	while ind > 0:
		ans += fenwick[ind]
		ind -= ind & -ind
	return ans

def dfs(adj, vis, u, l):
	vis[u] = 1
	l.add(u)
	for i in adj[u]:
		if vis[i] == 0:
			dfs(adj, vis, i, l)
mod = 10 ** 9 + 7
ma = 1002
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def dfs(i, j, arr, vis, n, m):
	vis[i][j] = 1
	for x in range(4):
		mx = i + dx[x]
		my = j + dy[x]
		if mx >= 0 and mx < n and (my >= 0) and (my < m) and (vis[mx][my] == 0):
			if arr[i][j] >= arr[mx][my]:
				dfs(mx, my, arr, vis, n, m)

def dfs(a, vis, node, c):
	vis[node] = 1
	c[0] += 1
	if vis[a[node]] == 0:
		dfs(a, vis, a[node], c)
mod = 998244353

def f(n):
	if n % 4 == 0:
		return n
	if n % 4 == 1:
		return 1
	if n % 4 == 2:
		return n + 1
	return 0

def cn(n):
	s = str(n)
	if s == s[::-1]:
		return True
	return False

def f(n):
	i = 1
	res = 0
	while i <= math.sqrt(n):
		if n % i == 0:
			if cn(i):
				res += 1
			k = n // i
			if i != k and cn(k):
				res += 1
		i = i + 1
	return res
mod = 10 ** 9 + 7

def finv(p, q):
	expo = 0
	expo = mod - 2
	while expo:
		if expo & 1:
			p = p * q % mod
		q = q * q % mod
		expo >>= 1
	return p

def solve():
	(n, r) = inp()
	a = lis()
	b = lis()
	c = [[a[i] - b[i], a[i]] for i in range(n)]
	c.sort()
	ans = 0
	for i in range(n):
		if c[i][1] > r:
			continue
		res = (r - c[i][1] + c[i][0]) // c[i][0]
		ans += res
		r -= res * c[i][0]
	print(ans)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, r) = map(int, input().split())
	cost = list(map(int, input().split()))
	dis = list(map(int, input().split()))
	crr = sorted(zip(cost, dis), key=lambda a: a[0] - a[1])
	nosw = 0
	for (i, j) in crr:
		d = max(0, (r - j) // (i - j))
		nosw += d
		r -= d * (i - j)
		if r == 0:
			break
	print(nosw)


t = int(input())
for i in range(t):
	(n, r) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [(a[i] - b[i], a[i]) for i in range(n)]
	c.sort(key=lambda x: [-x[0], -x[1]])
	cnt = 0
	while c and r:
		(amt, idx) = c.pop()
		if r >= idx:
			x = (r - idx) // amt
			cnt += x
			r -= x * amt
			if r >= idx:
				cnt += 1
				r -= amt
	print(cnt)


import itertools
import collections, math
from collections import defaultdict
from collections import Counter
import sys
import heapq
from heapq import *
for t in range(int(input())):
	(n, R) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	z = []
	for (x, y) in zip(a, b):
		z.append([x - y, x])
	z.sort()
	ans = 0
	i = 0
	while i < n:
		(diff, price) = z[i]
		if R >= price:
			units = math.ceil((R - price + 1) / diff)
			ans += units
			R -= units * diff
		i += 1
	print(ans)


for _ in range(int(input())):
	(n, r) = map(int, input().split())
	ori = list(map(int, input().split()))
	cb = list(map(int, input().split()))
	eff = []
	for i in range(n):
		eff.append([ori[i] - cb[i], i])
	eff.sort()
	mini = min(ori)
	ans = 0
	while r >= mini:
		i = 0
		while i < n and r >= mini:
			if ori[eff[i][1]] <= r:
				r -= ori[eff[i][1]]
				ans += 1
				ans += r // eff[i][0]
				r = r % eff[i][0] + cb[eff[i][1]]
			else:
				i += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, r) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = sorted(((a[j] - b[j], a[j]) for j in range(n)))
	ans = 0
	for (x, y) in c:
		if y <= r:
			v = (r - y) // x + 1
			r -= v * x
			ans += v
	print(ans)


def rec(a, b, r):
	ans = 0
	s = []
	for j in range(len(a)):
		diff = a[j] - b[j]
		s.append([diff, a[j], b[j]])
	s.sort(key=getFirst)
	j = 0
	while j < len(s):
		a = s[j][1]
		b = s[j][2]
		diff = s[j][0]
		c = max(0, (r - b) // diff)
		ans += c
		if c == 0:
			j += 1
		else:
			r = r - c * diff
			j = 0
	return ans

def getFirst(l):
	return l[0]
t = int(input())
for i in range(t):
	l = list(map(int, input().split(' ')))
	(n, r) = (l[0], l[1])
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	s = []
	print(rec(a, b, r))


for i in range(int(input())):
	(n, r) = map(int, input().split())
	ar = list(map(int, input().split()))
	cb = list(map(int, input().split()))
	arr = []
	m = float('inf')
	for i in range(n):
		m = min(m, ar[i])
		arr.append([ar[i], cb[i], ar[i] - cb[i]])
	arr.sort(key=lambda x: x[2])
	ans = 0
	i = 0
	while i < n:
		cost = arr[i][0]
		cashb = arr[i][1]
		while r >= cost:
			q = r // cost
			rem = r % cost
			ans += q
			r = rem + cashb * q
		i += 1
	print(ans)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	l = list(map(int, input().split()))
	c = list(map(int, input().split()))
	b = []
	m = l[0]
	for i in range(x):
		b.append([l[i] - c[i], i])
		if l[i] < m:
			m = l[i]
	z = sorted(b)
	count = 0
	for i in z:
		a = i[1]
		if y == 0 or y < m:
			break
		while y > 0:
			s = y // l[a]
			if s == 0:
				break
			y -= s * l[a]
			count += s
			y += s * c[a]
	print(count)


t = int(input())
while t:
	t -= 1
	(n, b_) = 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(n)]
	c.sort(key=lambda x: x[2])
	ans = 0
	for elem in c:
		while b_ >= elem[0]:
			temp = int(b_ / elem[0])
			ans += temp
			b_ = b_ - temp * elem[0] + temp * elem[1]
	print(ans)


def buyingSweets():
	for _ in range(int(input())):
		(n, r) = map(int, input().split())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		arr = []
		for i in range(n):
			arr.append([a[i], b[i]])
		arr.sort(key=lambda x: x[0])
		arr.sort(key=lambda x: x[0] - x[1])
		ans = 0
		for i in range(n):
			if r - arr[i][0] >= 0:
				temp = (r - arr[i][0]) // (arr[i][0] - arr[i][1])
				ans += temp
				r -= temp * (arr[i][0] - arr[i][1])
			while r >= arr[i][0]:
				ans += 1
				r -= arr[i][0] - arr[i][1]
		print(ans)
buyingSweets()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = [int(x) for x in input().split()]
	br = [int(x) for x in input().split()]
	res = [[ar[i] - br[i], ar[i], br[i]] for i in range(n)]
	ct = 0
	res.sort()
	for i in range(n):
		if m <= 0:
			break
		if res[i][1] <= m:
			q = (m - res[i][1]) // res[i][0] + 1
			ct += q
			m -= q * res[i][0]
	print(ct)


t = int(input())
for i in range(t):
	(n, r) = 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)]
	d = list(zip(a, c))
	d.sort(key=lambda x: x[1])
	cnt = 0
	for x in d:
		if x[0] > r:
			continue
		r -= x[0]
		cnt += 1
		cnt += r // x[1]
		r = r % x[1]
		r += x[0] - x[1]
	print(cnt)


for _ in range(int(input())):
	(n, money) = 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]))
	c.sort()
	ans = 0
	for i in range(n):
		effective_cost = c[i][0]
		actual_cost = c[i][1]
		cashback = actual_cost - effective_cost
		if money < actual_cost:
			continue
		money -= actual_cost
		ans += 1
		ans += money // effective_cost
		money %= effective_cost
		money += cashback
	print(ans)