Polycarp is wondering about buying a new computer, which costs $c$ tugriks. To do this, he wants to get a job as a programmer in a big company.

There are $n$ positions in Polycarp's company, numbered starting from one. An employee in position $i$ earns $a[i]$ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $1$ and has $0$ tugriks.

Each day Polycarp can do one of two things:

If Polycarp is in the position of $x$, then he can earn $a[x]$ tugriks.

If Polycarp is in the position of $x$ ($x < n$) and has at least $b[x]$ tugriks, then he can spend $b[x]$ tugriks on an online course and move to the position $x+1$.

For example, if $n=4$, $c=15$, $a=[1, 3, 10, 11]$, $b=[1, 2, 7]$, then Polycarp can act like this:

On the first day, Polycarp is in the $1$-st position and earns $1$ tugrik. Now he has $1$ tugrik;

On the second day, Polycarp is in the $1$-st position and move to the $2$-nd position. Now he has $0$ tugriks;

On the third day, Polycarp is in the $2$-nd position and earns $3$ tugriks. Now he has $3$ tugriks;

On the fourth day, Polycarp is in the $2$-nd position and is transferred to the $3$-rd position. Now he has $1$ tugriks;

On the fifth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $11$ tugriks;

On the sixth day, Polycarp is in the $3$-rd position and earns $10$ tugriks. Now he has $21$ tugriks;

Six days later, Polycarp can buy himself a new computer.

Find the minimum number of days after which Polycarp will be able to buy himself a new computer.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow.

The first line of each test case contains two integers $n$ and $c$ ($2 \le n \le 2 \cdot 10^5$, $1 \le c \le 10^9$) — the number of positions in the company and the cost of a new computer.

The second line of each test case contains $n$ integers $a_1 \le a_2 \le \ldots \le a_n$ ($1 \le a_i \le 10^9$).

The third line of each test case contains $n - 1$ integer $b_1, b_2, \ldots, b_{n-1}$ ($1 \le b_i \le 10^9$).

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case, output the minimum number of days after which Polycarp will be able to buy a new computer.


-----Examples-----

Input
3
4 15
1 3 10 11
1 2 7
4 100
1 5 10 50
3 14 12
2 1000000000
1 1
1
Output
6
13
1000000000


-----Note-----

None

Difficulty: HARD
Tags: Dynamic programming

Complete search

Implementation

Greedy algorithms
Skill types: Dynamic programming

Complete search

Greedy algorithms

Starter code:

Solutions:
import math
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	days = 0
	dp = [(0, 0)]
	cost = 0
	i = 0
	while True:
		if i < n - 1 and b[i] <= c:
			x = math.ceil((b[i] - cost) / a[i])
			days += x
			dp.append((cost + x * a[i], days))
		else:
			x = math.ceil((c - cost) / a[i])
			days += x
			break
		if dp[-1][0] >= c:
			break
		else:
			cost = dp[-1][0] - b[i]
			days += 1
			i += 1
	min_days = days
	for i in range(1, len(dp)):
		min_days = min(min_days, dp[i][1] + math.ceil((c - dp[i][0]) / a[i - 1]))
	print(min_days)


import math
t = int(input())
for i in range(t):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	days = 0
	cur = 0
	bal = 0
	ans = int(1e+18)
	for i in range(n):
		ans = min(ans, max(0, cur + math.ceil((c - bal) / a[i])))
		if i < n - 1:
			nd = max(0, math.ceil((b[i] - bal) / a[i]))
			bal += a[i] * nd - b[i]
		cur += nd + 1
	print(ans)


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, log2, sqrt, gcd
import bisect
import sys
import copy

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, c) = get_ints()
	a = get_array()
	b = get_array()
	mini = inf
	cnt = 0
	tot = 0
	mini = min(mini, ceil(c / a[0]))
	for i in range(1, len(a)):
		days = max(0, ceil((b[i - 1] - tot) / a[i - 1]))
		tot += days * a[i - 1]
		cnt += days + 1
		tot -= b[i - 1]
		mini = min(mini, cnt + ceil((c - tot) / a[i]))
	print(mini)


import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	c = int(l[1])
	l = input().split()
	li = [int(i) for i in l]
	b = input().split()
	bi = [int(i) for i in b]
	bi.append(0)
	days = 0
	extra = 0
	maxa = 10 ** 18
	for i in range(n):
		req = c - extra
		if req < 0:
			continue
		maxa = min(maxa, days + (req + li[i] - 1) // li[i])
		if bi[i] <= extra:
			nod = 1
		else:
			nod = 1 + (bi[i] - extra + li[i] - 1) // li[i]
		days += nod
		extra += (nod - 1) * li[i]
		extra -= bi[i]
	print(maxa)


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 math import ceil
for _ in range(rn()):
	(n, c) = rns()
	a = rl()
	b = rl()
	b.insert(0, 0)
	dp = n * [0]
	time = n * [0]
	rem = n * [0]
	dp[0] = ceil(c / a[0])
	for i in range(1, n):
		time[i] = time[i - 1] + ceil((b[i] - rem[i - 1]) / a[i - 1]) + 1
		rem[i] = a[i - 1] - (b[i] - rem[i - 1]) % a[i - 1]
		if rem[i] == a[i - 1]:
			rem[i] = 0
		poss = ceil((c - rem[i]) / a[i]) + time[i]
		dp[i] = min(dp[i - 1], poss)
	print(dp[-1])


import sys
import math
from collections import defaultdict, Counter, deque
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')
t = int(input())
for i in range(t):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 10 ** 9
	have = 0
	prev = 0
	for j in range(n):
		req = c - have
		ans = min(ans, prev + (req + a[j] - 1) // a[j])
		if j == n - 1:
			break
		days = max(0, (b[j] - have + a[j] - 1) // a[j])
		prev += days + 1
		have = have + days * a[j] - b[j]
	print(ans)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

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

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	(n, k) = mp()
	arr = lmp()
	barr = lmp()
	d = 0
	i = 0
	c = 0
	mn = inf
	while i < n - 1:
		mn = min(mn, d + ceil(k - c, arr[i]))
		td = min(ceil(k - c, arr[i]), ceil(barr[i] - c, arr[i]))
		c += td * arr[i] - barr[i]
		i += 1
		d += td + 1
	mn = min(mn, d + ceil(k - c, arr[i]))
	print(mn)


from typing import List
import math

def solve(N: int, C: int, pos: List[int], proms: List[int]) -> int:
	day = 0
	curr = 0
	min_days = math.ceil(C / pos[0])
	for i in range(N - 1):
		new_days = math.ceil((proms[i] - curr) / pos[i])
		day += new_days
		curr += new_days * pos[i]
		curr -= proms[i]
		day += 1
		min_days = min(min_days, day + math.ceil((C - curr) / pos[i + 1]))
	return min_days
test_cases = int(input())
for _ in range(test_cases):
	(N, C) = list(map(int, input().split()))
	pos = list(map(int, input().split()))
	proms = list(map(int, input().split()))
	print(solve(N, C, pos, proms))


import math
import sys

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

def solve(N, C, A, B):
	money = 0
	ans = float('inf')
	last = 0
	for i in range(len(B)):
		ans = min(ans, math.ceil((C - money) / A[i]) + last)
		m = math.ceil((B[i] - money) / A[i])
		money += m * A[i] - B[i]
		last += 1 + m
	ans = min(ans, math.ceil((C - money) / A[-1]) + last)
	return ans
T = int(input())
for _ in range(T):
	(N, C) = map(int, input().split())
	A = get_ints()
	B = get_ints()
	print(solve(N, C, A, B))


t = int(input())
for _ in range(t):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(day, left) = ([0] * (n + 1), [0] * (n + 1))
	now = 0
	for i in range(n - 1):
		mx = a[i]
		if b[i] <= now:
			day[i + 1] = day[i] + 1
			now -= b[i]
		else:
			cost = (b[i] - now + a[i] - 1) // a[i]
			day[i + 1] = day[i] + cost + 1
			now = now + cost * a[i] - b[i]
		left[i + 1] = now
	(l, r) = (1, 10 ** 9)
	while l <= r:
		mid = (l + r) // 2

		def ok(mid):
			for i in range(n):
				if day[i] > mid:
					break
				if (mid - day[i]) * a[i] + left[i] >= c:
					return True
			return False
		if ok(mid):
			r = mid - 1
		else:
			l = mid + 1
	print(l)


def ceil(a, b):
	if a % b:
		return a // b + 1
	else:
		return a // b
for testis in range(int(input())):
	(n, c) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = 10 ** 20
	curr = 0
	time = 0
	for i in range(n):
		cans = ceil(c - curr, a[i])
		ans = min(ans, time + cans)
		if i != n - 1:
			time_for_next_pos = ceil(b[i] - curr, a[i])
			curr = curr + (a[i] * time_for_next_pos - b[i])
			time += time_for_next_pos + 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
from math import inf

def main():
	for _ in range(int(input())):
		(n, c) = map(int, input().split())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		(x, y, mi) = (0, 0, inf)
		for i in range(n):
			z = (c - x + a[i] - 1) // a[i]
			mi = min(mi, y + z)
			if i != n - 1:
				z = (b[i] - x + a[i] - 1) // a[i]
				y += z
				zz = x + z * a[i]
				x = zz - b[i]
			y += 1
		print(mi)
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')
main()


import sys
input = sys.stdin.readline
from collections import Counter
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	cur = 0
	ans = float('inf')
	pre = 0
	for i in range(n - 1):
		k = (c - cur + A[i] - 1) // A[i]
		ans = min(ans, pre + k)
		p = (B[i] - cur + A[i] - 1) // A[i]
		pre += p + 1
		cur = cur + p * A[i] - B[i]
	k = (c - cur + A[-1] - 1) // A[-1]
	ans = min(ans, pre + k)
	print(ans)


import math

def saving_duration(x, y):
	return 0 if x <= 0 else math.ceil(x / y)
t = int(input())
for _ in range(t):
	(n, c) = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	time = 0
	earn = 0
	ans = float('inf')
	for i in range(n - 1):
		ans = min(ans, time + saving_duration(c - earn, a[i]))
		tt = saving_duration(b[i] - earn, a[i])
		time += tt
		time += 1
		earn += tt * a[i]
		earn -= b[i]
	ans = min(ans, time + saving_duration(c - earn, a[-1]))
	print(ans)


import math
t = int(input())
for i in range(t):
	(n, c) = map(int, input().strip().split(' '))
	a1 = list(map(int, input().strip().split(' ')))
	b1 = list(map(int, input().strip().split(' ')))
	l = []
	k1 = 0
	reserve = 0
	for j in range(n):
		if j == 0:
			l.append(math.ceil(c / a1[j]))
		else:
			k1 += math.ceil((b1[j - 1] - reserve) / a1[j - 1]) + 1
			reserve += math.ceil((b1[j - 1] - reserve) / a1[j - 1]) * a1[j - 1] - b1[j - 1]
			l.append(k1 + math.ceil((c - reserve) / a1[j]))
	print(min(l))


def cl(a, b):
	return a // b + int(bool(a % b))
for _ in range(int(input())):
	(n, c) = [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 and len(b) == n - 1
	dp = [None] * n
	res = [None] * n
	dp[0] = 0
	res[0] = 0
	for i in range(1, n):
		x = cl(max(0, b[i - 1] - res[i - 1]), a[i - 1])
		dp[i] = dp[i - 1] + x + 1
		res[i] = res[i - 1] - b[i - 1] + x * a[i - 1]
		assert res[i] >= 0
	ans = dp[0] + cl(max(0, c - res[0]), a[0])
	for i in range(n):
		ans = min(ans, dp[i] + cl(max(0, c - res[i]), a[i]))
	print(ans)


import sys

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

def solve():
	(n, c) = [int(_) for _ in input().split()]
	a = [int(_) for _ in input().split()]
	b = [int(_) for _ in input().split()] + [0]
	cur_amount = 0
	cur = 0
	ans = sys.maxsize
	for i in range(0, n):
		ans = min(ans, cur + max(0, c - cur_amount + a[i] - 1) // a[i])
		new_days = max(0, b[i] - cur_amount + a[i] - 1) // a[i]
		cur += new_days + 1
		cur_amount += a[i] * new_days - b[i]
	print(ans)
main()


import sys

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

def ceil(x, y):
	return (x + y - 1) // y

def slv():
	(n, c) = map(int, input().split())
	salary = list(map(int, input().split()))[::-1]
	promotion_cost = list(map(int, input().split()))[::-1]
	ans = 1 << 128
	left_money = 0
	prev_day = 0
	for finish_post in range(n):
		earning = salary.pop()
		if left_money < c:
			more_need_day = ceil(c - left_money, earning)
			ans = min(ans, prev_day + more_need_day)
			if finish_post < n - 1:
				prom_cost = promotion_cost.pop()
				more_need_day_for_promote = 0
				if left_money < prom_cost:
					more_need_day_for_promote = ceil(prom_cost - left_money, earning)
					left_money = earning * more_need_day_for_promote + left_money - prom_cost
					prev_day += more_need_day_for_promote
					prev_day += 1
				else:
					more_need_day_for_promote = 0
					left_money -= prom_cost
					prev_day += more_need_day_for_promote
					prev_day += 1
		else:
			ans = min(ans, prev_day)
			break
	print(ans)
	return

def main():
	t = int(input())
	for i in range(t):
		slv()
	return
main()


def ceil(x, y):
	if x <= 0:
		return 0
	return (x + y - 1) // y

def solve():
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	rem = 0
	su = 0
	ans = ceil(c, a[0])
	for (i, v) in enumerate(a[:n - 1]):
		d = ceil(b[i] - rem, v)
		su += d + 1
		rem += d * v - b[i]
		ans = min(ans, su + ceil(c - rem, a[i + 1]))
	print(ans)

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


for i in range(int(input())):
	(n, c) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	d = 0
	x = 0
	d1 = -1
	for i in range(n):
		d2 = d + max(0, -((x - c) // a[i]))
		if d1 == -1 or d2 < d1:
			d1 = d2
		if i != n - 1:
			d += max(0, -((x - b[i]) // a[i])) + 1
			x = x + max(0, -((x - b[i]) // a[i])) * a[i] - b[i]
	print(d1)


from math import ceil
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(days, store) = (0, 0)
	mini = 99999999999999999
	cur = 0
	for i in range(n):
		mini = min(mini, ceil(max(0, c - store) / a[i]) + cur + i)
		days = max(0, ceil((b[i] - store) / a[i])) if i < n - 1 else 0
		store += a[i] * days - b[i] if i < n - 1 else 0
		cur += days
	print(mini)


for __ in range(int(input())):
	(n, c) = list(map(int, input().split()))
	ar1 = list(map(int, input().split()))
	ar2 = list(map(int, input().split()))
	kevukeka = c
	ans = 10 ** 9
	days_gone = 0
	money2_1 = 0
	for i in range(n - 1):
		days1 = (c + ar1[i] - 1) // ar1[i] + days_gone
		days2_1 = (ar2[i] - money2_1 + ar1[i] - 1) // ar1[i]
		money2_1 += ar1[i] * days2_1 - ar2[i]
		c = kevukeka - money2_1
		days_gone += days2_1 + 1
		ans = min(ans, days1)
	days1 = (c + ar1[n - 1] - 1) // ar1[n - 1] + days_gone
	ans = min(ans, days1)
	print(ans)


from math import ceil
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cur = 0
	curd = 0
	ans = 10 ** 20
	for i in range(n):
		temp = ceil((c - cur) / a[i])
		ans = min(ans, curd + temp)
		if i < n - 1:
			temp = ceil((b[i] - cur) / a[i])
			curd += temp
			temp1 = cur + temp * a[i]
			cur = temp1 - b[i]
		curd += 1
	print(ans)


def helper(a, b, c):
	pool = [0] * len(a)
	pool[0] = (c - 1) // a[0] + 1
	d = 0
	m = 0
	for i in range(1, len(a)):
		d += (b[i - 1] - m - 1) // a[i - 1] + 1 + 1
		m = (m - b[i - 1]) % a[i - 1]
		tc = c - m
		pool[i] = d + (tc - 1) // a[i] + 1
	return min(pool)
t = int(input())
for i in range(t):
	(n, c) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	b = list(map(int, input().split(' ')))
	print(helper(a, b, c))


from math import ceil
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	wages = [*map(int, input().split())]
	promos = [*map(int, input().split())]
	ans = 1000000000
	days = 0
	cash = 0
	for i in range(n):
		ans = min(ans, days + ceil((c - cash) / wages[i]))
		if i < n - 1:
			days_to_promo = ceil((promos[i] - cash) / wages[i])
			days += days_to_promo + 1
			cash = cash + days_to_promo * wages[i] - promos[i]
	print(ans)


def main():
	t = int(input())
	allans = []
	for _ in range(t):
		(n, computerCost) = readIntArr()
		a = readIntArr()
		b = readIntArr()
		c = [None for _ in range(n)]
		d = [None for _ in range(n)]
		money = 0
		day = 0
		c[0] = 0
		d[0] = 0
		for i in range(n - 1):
			toEarn = max(0, b[i] - money)
			nDays = (toEarn + a[i] - 1) // a[i]
			day += nDays
			money += nDays * a[i] - b[i]
			day += 1
			c[i + 1] = day
			d[i + 1] = money
			assert money >= 0
		earliestDay = inf
		for i in range(n):
			day = c[i]
			money = d[i]
			toEarn = max(0, computerCost - money)
			additionalDays = (toEarn + a[i] - 1) // a[i]
			earliestDay = min(earliestDay, day + additionalDays)
		allans.append(earliestDay)
	multiLineArrayPrint(allans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

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

def makeArr(defaultVal, dimensionArr):
	dv = defaultVal
	da = dimensionArr
	if len(da) == 1:
		return [dv for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
	ans = float('inf')
	(n, c) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	b = list(map(int, stdin.readline().split()))
	nhave = 0
	nday = 0
	for i in range(n):
		plusday = max(0, (c - nhave + a[i] - 1) // a[i])
		ans = min(ans, nday + plusday + i)
		if i == n - 1:
			break
		plusday = max(0, (b[i] - nhave + a[i] - 1) // a[i])
		nhave = nhave + plusday * a[i] - b[i]
		nday += plusday
	print(ans)


from sys import stdin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

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

def lsi():
	return list(si())
t = ii()
while t > 0:
	(n, st) = mi()
	a = li()
	b = li()
	ans = 10 ** 9 * 2
	cur_days = 0
	cur_pos = 0
	cur_money = 0
	while cur_pos < n - 1:
		ans = min(ans, cur_days + max(st - cur_money, 0) // a[cur_pos] + (1 if max(st - cur_money, 0) % a[cur_pos] != 0 else 0))
		need_days = max(b[cur_pos] - cur_money, 0) // a[cur_pos] + (1 if max(b[cur_pos] - cur_money, 0) % a[cur_pos] != 0 else 0)
		left_money = cur_money + a[cur_pos] * need_days - b[cur_pos]
		cur_days += need_days + 1
		cur_money = left_money
		cur_pos += 1
	ans = min(ans, cur_days + max(st - cur_money, 0) // a[cur_pos] + (1 if max(st - cur_money, 0) % a[cur_pos] != 0 else 0))
	print(ans)
	t -= 1


import time
import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import bisect_left, bisect_right
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string, heapq as h
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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 getInt():
	return int(input())

def getStrs():
	return input().split()

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

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]

def getBin():
	return list(map(int, list(input())))

def isInt(s):
	return '0' <= s[0] <= '9'

def ceil_(a, b):
	return a // b + (a % b > 0)
MOD = 10 ** 9 + 7

def solve():
	(N, C) = getInts()
	A = getInts()
	B = getInts()
	curr = 0
	day = 0
	ans = 10 ** 18
	for i in range(N):
		ans = min(ans, day + max(0, ceil_(C - curr, A[i])))
		if i == N - 1:
			break
		to_next = max(ceil_(B[i] - curr, A[i]), 0)
		curr += to_next * A[i]
		curr -= B[i]
		day += to_next + 1
	return ans
for _ in range(getInt()):
	print(solve())


import math

def solve(n, c, a, b):
	money = 0
	t = 0
	timemin = float('inf')
	res = []
	for i in range(n):
		timehere = t + math.ceil((c - money) / a[i])
		timemin = min(timemin, timehere)
		if i < n - 1:
			surp = math.ceil((b[i] - money) / a[i])
			t += surp + 1
			money += surp * a[i] - b[i]
	print(timemin)
t = int(input())
for i in range(t):
	(n, c) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	solve(n, c, a, b)


for _ in range(int(input())):
	(n, c) = map(int, input().split())
	(a, b) = (list(map(int, input().split())), list(map(int, input().split())) + [0])
	balance = 0
	cur = 0
	ans = 10 ** 18 + 1
	for i in range(n):
		ans = min(ans, cur + max(0, c - balance + a[i] - 1) // a[i])
		new = max(0, b[i] - balance + a[i] - 1) // a[i]
		cur += new + 1
		balance += a[i] * new - b[i]
	print(ans)


def solve(A, B, n, c):
	days = 0
	wallet = 0
	ans = float('inf')
	for job in range(n):
		wage = A[job]
		left = max(c - wallet, 0)
		tim = (left + wage - 1) // wage
		ans = min(ans, days + tim)
		if job == n - 1:
			break
		course_fee = B[job]
		left = max(course_fee - wallet, 0)
		tim = (left + wage - 1) // wage
		days += tim + 1
		wallet += wage * tim - course_fee
	return ans
for case in range(int(input())):
	(n, c) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = solve(A, B, n, c)
	print(ans)


import math
t = int(input())
for _ in range(t):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	days = [0 for i in range(n)]
	coins = [0 for i in range(n)]
	for i in range(1, n):
		days[i] = days[i - 1] + math.ceil((b[i - 1] - coins[i - 1]) / a[i - 1]) + 1
		coins[i] = coins[i - 1] + (days[i] - days[i - 1] - 1) * a[i - 1] - b[i - 1]
	print(min([days[i] + math.ceil((c - coins[i]) / a[i]) for i in range(n)]))


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
import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	ls = list(map(int, input().split()))
	ans = 10 ** 20
	day = 0
	a = 0
	for i in range(n):
		if i == n - 1:
			ans = min(ans, math.ceil(max(0, m - a) / arr[i]) + day)
		else:
			ans = min(ans, math.ceil(max(0, m - a) / arr[i]) + day)
			re = math.ceil(max(ls[i] - a, 0) / arr[i])
			a += re * arr[i] - ls[i]
			day += re
			day += 1
	print(ans)


from collections import deque, defaultdict
from math import sqrt, ceil, factorial, floor, inf, gcd
import bisect
import sys
import copy

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, c) = get_ints()
	a = get_array()
	b = get_array()
	min_days = ceil(c / a[0])
	money_now = 0
	days_required = 0
	for i in range(1, n):
		tmp_required = ceil((b[i - 1] - money_now) / a[i - 1])
		days_required += tmp_required + 1
		money_now = a[i - 1] * tmp_required - (b[i - 1] - money_now)
		min_days = min(min_days, days_required + ceil((c - money_now) / a[i]))
	print(min_days)


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

def calculateMin(a, b):
	days = 0
	money = 0
	ans = float('inf')
	for i in range(n - 1):
		ans = min(ans, ceil(c - money, a[i]) + days)
		toReachNext = ceil(b[i] - money, a[i])
		days += 1 + toReachNext
		money += a[i] * toReachNext - b[i]
	ans = min(ans, ceil(c - money, a[-1]) + days)
	return ans
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(calculateMin(a, b))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, c) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	temp = [int(x) for x in input().split()]
	(curr, days, ans) = (0, 0, sys.maxsize)
	for i in range(n):
		ans = min(ans, days + (c - curr + arr[i] - 1) // arr[i])
		if i != n - 1:
			now = (temp[i] - curr + arr[i] - 1) // arr[i]
			days += now + 1
			curr = curr + now * arr[i] - temp[i]
	print(ans)


from math import ceil, inf

def main(n, c, a, b):
	reach_day = [0] * n
	remain = [0] * n
	res = inf
	for i in range(n):
		if c < 0:
			break
		expected = c - remain[i]
		day = int(ceil(expected / a[i]))
		res = min(res, reach_day[i] + day)
		if i < n - 1:
			expected = b[i] - remain[i]
			day = int(ceil(expected / a[i]))
			reach_day[i + 1] = reach_day[i] + day + 1
			remain[i + 1] = day * a[i] - expected
	print(res)
t = int(input())
for _ in range(t):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	main(n, c, a, b)


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def ceil(a, b):
	if a % b:
		return a // b + 1
	else:
		return a // b
for _ in range(int(input())):
	(n, c) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	ans = 10 ** 20
	curr = 0
	time = 0
	for i in range(n):
		cans = ceil(c - curr, a[i])
		ans = min(ans, time + cans)
		if i != n - 1:
			jtime = ceil(b[i] - curr, a[i])
			curr = a[i] * jtime + curr - b[i]
			time += jtime + 1
	print(ans)


for nt in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = (c - 1) // a[0] + 1
	d = (b[0] - 1) // a[0] + 1
	p = d * a[0]
	for i in range(1, n):
		p -= b[i - 1]
		d += 1
		ans = min(ans, d + (c - p - 1) // a[i] + 1)
		if i == n - 1:
			break
		d += (b[i] - p - 1) // a[i] + 1
		p += ((b[i] - p - 1) // a[i] + 1) * a[i]
	print(ans)


from sys import stdin
readline = stdin.readline

def readInt():
	return int(readline())

def readInts():
	return list(map(int, readline().split()))
t = readInt()
for i in range(t):
	(n, c) = readInts()
	a_list = readInts()
	b_list = readInts()
	days_to_reach = [(0, 0)]
	days_to_finish = []
	for i in range(0, n - 1):
		(days_curr, money_curr) = days_to_reach[i]
		if money_curr >= b_list[i]:
			days_to_reach.append((days_curr + 1, money_curr - b_list[i]))
		else:
			days_work = (b_list[i] - money_curr + a_list[i] - 1) // a_list[i]
			remaining = money_curr + days_work * a_list[i] - b_list[i]
			days_to_reach.append((days_curr + days_work + 1, remaining))
	for i in range(0, n):
		(days_curr, money_curr) = days_to_reach[i]
		if money_curr >= c:
			days_to_finish.append(days_curr)
		else:
			days_finish = (c - money_curr + a_list[i] - 1) // a_list[i]
			days_to_finish.append(days_curr + days_finish)
	print(min(days_to_finish))


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
pr = lambda x: x

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def solve():
	for _ in range(int(input())):
		(n, c) = aj()
		A = aj()
		B = aj()
		ans = 1e+18
		cur = 0
		prev_days = 0
		for i in range(n):
			amt = max(0, c - cur)
			days_req = math.ceil(amt / A[i])
			ans = min(ans, prev_days + days_req)
			if i != n - 1:
				days_to_improve = math.ceil(max(0, B[i] - cur) / A[i])
				prev_days += days_to_improve + 1
				cur += days_to_improve * A[i]
				cur -= B[i]
		print(ans)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	from aj import *
except:
	pass
solve()


def solve(n, c, a, b):
	ds = [-1] * n
	s = 0
	d = 0
	ds[0] = -(-c // a[0])
	for i in range(n - 1):
		if s >= b[i]:
			s -= b[i]
			d += 1
		else:
			dd = -(-(b[i] - s) // a[i])
			d += dd + 1
			s += dd * a[i] - b[i]
		ds[i + 1] = d + (-(-(c - s) // a[i + 1]) if c > s else 0)
		2 + 2
	print(min(ds))
t = int(input())
for _ in range(t):
	(n, c) = map(int, input().split())
	(*a,) = map(int, input().split())
	(*b,) = map(int, input().split())
	solve(n, c, a, b)


for _ in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	money = 0
	ans = 0
	arr = []
	arr.append((c + a[0] - 1) // a[0])
	for i in range(1, n):
		cnt = (b[i - 1] + a[i - 1] - 1 - money) // a[i - 1] + 1
		ans += cnt
		money += (cnt - 1) * a[i - 1] - b[i - 1]
		arr.append(ans + (c - money + a[i] - 1) // a[i])
	print(min(arr))


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 25
MOD = pow(10, 9) + 7
BUFSIZE = 8192
from collections import defaultdict

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')
for _ in range(int(input())):
	(n, t) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))
	e = list(map(int, input().split(' ')))
	dp = [0] * n
	days = [0] * n
	days[0] = math.ceil(t / l[0])
	dp[0] = math.ceil(e[0] / l[0]) + 1
	extra = 0
	if e[0] % l[0]:
		extra = l[0] - e[0] % l[0]
	for i in range(1, n):
		days[i] = dp[i - 1] + (t - extra + l[i] - 1) // l[i]
		if i < n - 1:
			dp[i] = dp[i - 1] + 1 + (e[i] + l[i] - 1 - extra) // l[i]
			extra += (e[i] + l[i] - 1 - extra) // l[i] * l[i] - e[i]
	print(min(days))


I = lambda : [*map(int, input().split())]

def out(x):
	print(str(x))

def solve():
	(n, c) = I()
	a = I()
	b = I()
	best_d = 1000000009
	current_m = 0
	current_d = 0
	for i in range(n):
		wait = int((c - current_m + a[i] - 1) / a[i])
		best_d = min(best_d, wait + current_d)
		if i == n - 1:
			continue
		new_days = int(max(0, b[i] - current_m + a[i] - 1) / a[i])
		current_m += new_days * a[i]
		current_m -= b[i]
		current_d += new_days + 1
	out(best_d)
(t,) = I()
for i in range(t):
	solve()


import math

def main():
	t = int(input())
	for _ in range(t):
		(n, c) = (int(x) for x in input().split())
		L1 = [int(x) for x in input().split()]
		L2 = [int(x) for x in input().split()]
		print(solver(n, c, L1, L2))

def solver(n, c, L1, L2):
	minDays = math.ceil(c / L1[0])
	days = 0
	money = 0
	for i in range(n - 1):
		if days >= minDays:
			return minDays
		daysToBuy = math.ceil((c - money) / L1[i])
		if days + daysToBuy < minDays:
			minDays = days + daysToBuy
		daysToNextJob = math.ceil((L2[i] - money) / L1[i])
		if daysToNextJob > 0:
			days += daysToNextJob + 1
			money += daysToNextJob * L1[i] - L2[i]
		else:
			days += 1
			money -= L2[i]
	daysToBuy = math.ceil((c - money) / L1[n - 1])
	if days + daysToBuy < minDays:
		minDays = days + daysToBuy
	return minDays
main()


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	(n, k) = R()
	(*a,) = R()
	(*b,) = R()
	ans = inf
	s = 0
	d = 0
	for i in range(n):
		ans = min(ans, (k - s + a[i] - 1) // a[i] + d)
		if i != n - 1:
			d += (max(0, b[i] - s) + a[i] - 1) // a[i] + 1
			if s < b[i]:
				s = (a[i] - (b[i] - s) % a[i]) % a[i]
			else:
				s = s - b[i]
	print(ans)


def solve():
	(n, c) = input_as_list()
	a = input_as_list()
	b = input_as_list()
	ans = float('inf')
	(coins, time) = (0, 0)
	for i in range(n):
		ans = min(ans, time + ceil_div(c - coins, a[i]))
		if i < n - 1:
			days = ceil_div(b[i] - coins, a[i])
			time += days + 1
			coins += days * a[i] - b[i]
	print(ans)

def ceil_div(a, b):
	return max(0, (a + b - 1) // b)

def input_as_list():
	return [int(t) for t in input().split()]
for _ in range(int(input())):
	solve()


from heapq import heapify, heappush, heappop, heappushpop
from collections import defaultdict as dd, deque as dq, Counter as C
from math import factorial as f, ceil, gcd, sqrt, log
from bisect import bisect_left as bl, bisect_right as br
from itertools import combinations as c, permutations as p
from math import factorial as f, ceil, gcd, sqrt, log
from sys import stdin
input = stdin.readline
mp = lambda : map(int, input().split())
it = lambda : int(input())
ls = lambda : list(input().strip())
mt = lambda r: [ls() for _ in range(r)]
lcm = lambda a, b: a * b // gcd(a, b)
mod = 1000000007
for _ in range(it()):
	(a, b) = mp()
	fs = list(mp())
	se = list(mp())
	cur = 0
	day = 0
	ans = float('inf')
	i = 0
	while i < a - 1:
		ans = min(ans, day + ceil((b - cur) / fs[i]))
		l = ceil((se[i] - cur) / fs[i])
		day += l + 1
		cur += l * fs[i] - se[i]
		i += 1
	ans = min(ans, day + ceil((b - cur) / fs[a - 1]))
	print(ans)


import sys, os, io
import math, bisect, operator
(inf, mod) = (float('inf'), 10 ** 9 + 7)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int, input().split()))
(test,) = Neo()
for _ in range(test):
	(n, p) = Neo()
	A = Neo()
	B = Neo()
	(d, c) = (0, 0)
	Ans = [0] * n
	for i in range(n):
		Ans[i] = math.ceil((p - c) / A[i]) + d
		if i < n - 1:
			t = math.ceil((B[i] - c) / A[i])
			c += t * A[i]
			c -= B[i]
			d += t + 1
	print(min(Ans))


import sys
import math
from math import factorial, inf, gcd
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
sys.setrecursionlimit(10 ** 5)

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

def up(n, m):
	return (n + m - 1) // m
ti = 1
ti = int(input())
for ii in range(ti):
	(n, c) = rarray()
	a = rarray()
	b = rarray()
	day = [[inf, inf] for i in range(n)]
	day[0] = [0, 0]
	m = a[0]
	ans = up(c, a[0])
	for i in range(1, n):
		d = up(max(0, b[i - 1] - day[i - 1][1]), m)
		day[i][0] = day[i - 1][0] + d + 1
		day[i][1] = day[i - 1][1] + d * a[i - 1] - b[i - 1]
		m = max(m, a[i])
		ans = min(ans, day[i][0] + up(c - day[i][1], a[i]))
	print(ans)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
from collections import deque
BUFSIZE = 8192
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 main():
	t = int(input())
	for i in range(t):
		(n, cost) = map(int, input().split())
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		ans = math.ceil(cost / a[0])
		j = 1
		(cnt, c) = (0, 0)
		while j < n:
			if c < b[j - 1]:
				tmp = math.ceil((b[j - 1] - c) / a[j - 1])
				cnt += tmp + 1
				c = tmp * a[j - 1] - b[j - 1] + c
			else:
				cnt += 1
				c = c - b[j - 1]
			if cost >= c:
				ans = min(ans, cnt + math.ceil((cost - c) / a[j]))
			j += 1
		print(ans)
main()


from sys import stdin
from math import ceil
input = stdin.readline
for test in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split())) + [0]
	(days, pos_b, tur) = (0, 0, 0)
	arr = []
	for i in a:
		arr.append(max(ceil((c - tur) / i), 0) + days)
		t = max(ceil((b[pos_b] - tur) / i), 0)
		days += t + 1
		tur += t * i - b[pos_b]
		pos_b += 1
	print(min(arr))


import sys, math
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	(days, remCost) = (0, 0)
	best = sys.maxsize
	for i in range(n):
		best = min(best, days + max(0, math.ceil((c - remCost) / a[i])))
		if i < n - 1:
			day = max(0, math.ceil((b[i] - remCost) / a[i]))
			remCost = a[i] * day - b[i] + remCost
			days += day + 1
	print(best)


t = int(input())
for _ in range(t):
	(n, c) = map(int, input().split())
	A = [int(x) for x in input().split()]
	B = [int(x) for x in input().split()]
	mn = 1e309
	has = 0
	days = 0
	for i in range(n - 1):
		finish = (c - has + A[i] - 1) // A[i]
		mn = min(finish + days, mn)
		upgrade = (B[i] - has + A[i] - 1) // A[i]
		if upgrade > 0:
			days += upgrade
			has += upgrade * A[i]
		days += 1
		has -= B[i]
	finish = (c - has + A[-1] - 1) // A[-1]
	mn = min(finish + days, mn)
	print(mn)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

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

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, c) = value()
	a = array()
	b = array()
	ans = Ceil(c, a[0])
	days = 0
	cur = 0
	for i in range(1, n):
		days += 1
		need = max(0, b[i - 1] - cur)
		here = Ceil(need, a[i - 1])
		days += here
		cur += a[i - 1] * here - b[i - 1]
		ans = min(ans, days + Ceil(max(0, c - cur), a[i]))
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log, ceil
from collections import Counter
from pprint import pprint
from itertools import permutations
from bisect import bisect_right

def main(case):
	(n, c) = map(int, input().split())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	dohave = 0
	time = 0
	ans = float('inf')
	for i in range(n):
		if dohave > c:
			break
		ans = min(ans, time + ceil((c - dohave) / arr[i]))
		if i < n - 1:
			time += ceil(max(0, brr[i] - dohave) / arr[i])
			nw = dohave + arr[i] * ceil(max(0, brr[i] - dohave) / arr[i])
			dohave = nw - brr[i]
			assert dohave < arr[i]
		time += 1
	print(ans)
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')
for _ in range(int(input())):
	main(_ + 1)


from math import ceil
import sys
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	money = 0
	days = 0
	ans = sys.maxsize
	for i in range(n):
		ans = min(days + ceil((c - money) / a[i]), ans)
		if i == len(b):
			break
		r = ceil((b[i] - money) / a[i])
		money += r * a[i] - b[i]
		days += r + 1
	print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cur = 0
	tot = 0
	ans = 10 ** 12
	for i in range(n):
		ck = ceil(max(0, c - tot) / a[i])
		ans = min(ans, ck + cur)
		if i < n - 1:
			if tot >= b[i]:
				tot -= b[i]
				cur += 1
			else:
				ck = ceil((b[i] - tot) / a[i])
				tot += ck * a[i] - b[i]
				cur += ck + 1
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = 1234567890
	total = 0
	current = 0
	for i in range(n):
		ans = min(ans, total + max((c - current + a[i] - 1) // a[i], 0))
		if i < n - 1:
			q = (b[i] - current + a[i] - 1) // a[i]
			q = max(q, 0)
			total += q + 1
			current = current + a[i] * q - b[i]
	print(ans)


for _ in range(int(input())):
	(n, c) = map(int, input().split())
	arrA = list(map(int, input().split()))
	arrB = list(map(int, input().split()))
	daysToPos = 0
	curBal = 0
	ans = float('inf')
	for pos in range(n):
		if curBal >= c:
			ans = min(ans, daysToPos)
			break
		else:
			ans = min(ans, daysToPos + (c - curBal) // arrA[pos] + (1 if (c - curBal) % arrA[pos] else 0))
		if pos < n - 1:
			if arrB[pos] >= c:
				break
			if curBal >= arrB[pos]:
				daysToPos += 1
				curBal -= arrB[pos]
			else:
				daysToNext = (arrB[pos] - curBal) // arrA[pos] + (1 if (arrB[pos] - curBal) % arrA[pos] else 0)
				daysToPos += daysToNext + 1
				curBal += daysToNext * arrA[pos] - arrB[pos]
	print(ans)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
from math import inf, log2
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
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')

class LazySegmentTree:

	def __init__(self, array, func=max):
		self.n = len(array)
		self.size = 2 ** (int(log2(self.n - 1)) + 1) if self.n != 1 else 1
		self.func = func
		self.default = 0 if self.func != min else inf
		self.data = [self.default] * (2 * self.size)
		self.lazy = [0] * (2 * self.size)
		self.process(array)

	def process(self, array):
		self.data[self.size:self.size + self.n] = array
		for i in range(self.size - 1, -1, -1):
			self.data[i] = self.func(self.data[2 * i], self.data[2 * i + 1])

	def push(self, index):
		self.lazy[2 * index] += self.lazy[index]
		self.lazy[2 * index + 1] += self.lazy[index]
		self.data[2 * index] += self.lazy[index]
		self.data[2 * index + 1] += self.lazy[index]
		self.lazy[index] = 0

	def build(self, index):
		index >>= 1
		while index:
			self.data[index] = self.func(self.data[2 * index], self.data[2 * index + 1]) + self.lazy[index]
			index >>= 1

	def query(self, alpha, omega):
		res = self.default
		alpha += self.size
		omega += self.size + 1
		for i in range(len(bin(alpha)[2:]) - 1, 0, -1):
			self.push(alpha >> i)
		for i in range(len(bin(omega - 1)[2:]) - 1, 0, -1):
			self.push(omega - 1 >> i)
		while alpha < omega:
			if alpha & 1:
				res = self.func(res, self.data[alpha])
				alpha += 1
			if omega & 1:
				omega -= 1
				res = self.func(res, self.data[omega])
			alpha >>= 1
			omega >>= 1
		return res

	def update(self, alpha, omega, value):
		alpha += self.size
		omega += self.size + 1
		(l, r) = (alpha, omega)
		while alpha < omega:
			if alpha & 1:
				self.data[alpha] += value
				self.lazy[alpha] += value
				alpha += 1
			if omega & 1:
				omega -= 1
				self.data[omega] += value
				self.lazy[omega] += value
			alpha >>= 1
			omega >>= 1
		self.build(l)
		self.build(r - 1)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		k = 1 << 32
		for i in range(31, -1, -1):
			k //= 2
			val = pre_xor & k
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, p):
		ans = 0
		self.temp = self.root
		k = 1 << 32
		for i in range(31, -1, -1):
			k //= 2
			val = p & k
			if val == 0:
				if self.temp.right and self.temp.right.count > 0:
					self.temp = self.temp.right
					ans ^= k
				else:
					self.temp = self.temp.left
			elif self.temp.left and self.temp.left.count > 0:
				self.temp = self.temp.left
				ans ^= k
			else:
				self.temp = self.temp.right
		return ans
for ik in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))

	def find(x):
		cur = 0
		days = x
		now = 0
		while True:
			if now + days * a[cur] >= c:
				return True
			else:
				if cur == len(a) - 1:
					return False
				t = min(days, int(math.ceil((b[cur] - now) / a[cur])) + 1)
				days -= t
				now += (t - 1) * a[cur] - b[cur]
				cur += 1
			if days == 0:
				if now < c:
					return False
				return True
	st = 1
	end = int(math.ceil(c / a[0]))
	ans = end
	while st <= end:
		mid = (st + end) // 2
		if find(mid) == True:
			ans = mid
			end = mid - 1
		else:
			st = mid + 1
	print(ans)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
import sys
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

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

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(n, c) = li()
	a = li()
	b = li()
	ans = float('inf')
	money = curr_days = 0
	for i in range(n):
		right_now = (c - money) // a[i] + (1 if (c - money) % a[i] else 0)
		ans = min(ans, curr_days + right_now)
		if i == n - 1:
			break
		temp_days = math.ceil((b[i] - money) / a[i])
		curr_days += temp_days + 1
		money = abs(b[i] - money - temp_days * a[i])
	print(ans)


import sys, functools, collections, bisect, math, heapq
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, c) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	b = list(map(int, input().strip().split()))
	pre = 0
	day = 0
	ans = float('inf')
	for i in range(n):
		curr = max(0, math.ceil((c - pre) / arr[i]))
		if ans > curr + day:
			ans = curr + day
		if i == n - 1:
			continue
		y = max(0, math.ceil((b[i] - pre) / arr[i]))
		day += y + 1
		pre = y * arr[i] + pre - b[i]
	print(ans)


t = int(input())
for _ in range(t):
	(n, c) = [int(num) for num in input().strip().split(' ')]
	pos = [int(num) for num in input().strip().split(' ')]
	move = [int(num) for num in input().strip().split(' ')]
	res = int(1000000000000.0)
	x = 0
	d = 0
	for i in range(n - 1):
		a = pos[i]
		res = min(d + max(c - x, 0) // a + int(max(c - x, 0) % a != 0), res)
		d += max(move[i] - x, 0) // a + int(max(move[i] - x, 0) % a != 0) + 1
		x = x + a * (max(move[i] - x, 0) // a + int(max(move[i] - x, 0) % a != 0)) - move[i]
	res = min(d + max(c - x, 0) // pos[n - 1] + int(max(c - x, 0) % pos[n - 1] != 0), res)
	print(res)


import sys
input = sys.stdin.readline
cas = int(input())
while cas:
	cas -= 1
	(n, c) = map(int, input().split())
	d = [[0, 0] for i in range(n)]
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	tmp = 0
	for i in range(1, n):
		tt = (b[i - 1] - tmp + a[i - 1] - 1) // a[i - 1]
		d[i][0] = d[i - 1][0] + tt + 1
		d[i][1] = tmp + a[i - 1] * tt - b[i - 1]
		tmp = d[i][1]
	ans = 20 ** 9
	for i in range(n):
		ans = min(ans, d[i][0] + (c - d[i][1] + a[i] - 1) // a[i])
	print(ans)


from sys import stdin
from math import ceil

def updiv(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1
t = int(stdin.readline())
for _ in range(t):
	(n, c) = map(int, stdin.readline().split())
	a = [int(x) for x in stdin.readline().split()]
	b = [int(x) for x in stdin.readline().split()]
	d = [-1] * n
	r = [-1] * n
	d[0] = 0
	r[0] = 0
	for i in range(1, n):
		dd = updiv(b[i - 1] - r[i - 1], a[i - 1])
		d[i] = d[i - 1] + 1 + dd
		r[i] = dd * a[i - 1] - (b[i - 1] - r[i - 1])
	m = float('inf')
	for i in range(n):
		days = d[i] + updiv(c - r[i], a[i])
		m = min(days, m)
	print(m)


import sys
input = sys.stdin.readline

def solve():
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	dp = [None] * n
	dp[0] = (0, 0)
	ans = max((c + a[0] - 1) // a[0], 0)
	for i in range(1, n):
		(d, h) = dp[i - 1]
		s = a[i - 1]
		dn = max((b[i - 1] - h + s - 1) // s, 0)
		h += s * dn - b[i - 1]
		d += dn + 1
		dp[i] = (d, h)
		dn = max((c - h + a[i] - 1) // a[i], 0)
		ans = min(ans, d + dn)
	print(ans)
for i in range(int(input())):
	solve()


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
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')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

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

def N():
	return int(input())

def A(n):
	return [0] * n

def AI(n, x):
	return [x] * n

def A2(n, m):
	return [[0] * m for i in range(n)]

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

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]
from types import GeneratorType

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
mod = 10 ** 9 + 7
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	fact(x, mod)
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa.reverse()

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def floorsum(a, b, c, n):
	if a == 0:
		return b // c * (n + 1)
	if a >= c or b >= c:
		return floorsum(a % c, b % c, c, n) + b // c * (n + 1) + a // c * n * (n + 1) // 2
	m = (a * n + b) // c
	return n * m - floorsum(c, c - b - 1, a, m - 1)

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

def lowbit(n):
	return n & -n

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class ST:

	def __init__(self, arr):
		n = len(arr)
		mx = n.bit_length()
		self.st = [[0] * mx for i in range(n)]
		for i in range(n):
			self.st[i][0] = arr[i]
		for j in range(1, mx):
			for i in range(n - (1 << j) + 1):
				self.st[i][j] = max(self.st[i][j - 1], self.st[i + (1 << j - 1)][j - 1])

	def query(self, l, r):
		if l > r:
			return -inf
		s = (r + 1 - l).bit_length() - 1
		return max(self.st[l][s], self.st[r - (1 << s) + 1][s])

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		seen.add(u)
		for (v, w) in graph[u]:
			if v not in d or d[v] > d[u] + w:
				d[v] = d[u] + w
				heappush(heap, (d[v], v))
	return d

def bell(s, g):
	dis = AI(n, inf)
	dis[s] = 0
	for i in range(n - 1):
		for (u, v, w) in edge:
			if dis[v] > dis[u] + w:
				dis[v] = dis[u] + w
	change = A(n)
	for i in range(n):
		for (u, v, w) in edge:
			if dis[v] > dis[u] + w:
				dis[v] = dis[u] + w
				change[v] = 1
	return dis

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

def lis(nums):
	res = []
	for k in nums:
		i = bisect.bisect_left(res, k)
		if i == len(res):
			res.append(k)
		else:
			res[i] = k
	return len(res)

def RP(nums):
	n = len(nums)
	s = set(nums)
	d = {}
	for (i, k) in enumerate(sorted(s), 1):
		d[k] = i
	bi = BIT([0] * (len(s) + 1))
	ans = 0
	for i in range(n - 1, -1, -1):
		ans += bi.query(d[nums[i]] - 1)
		bi.update(d[nums[i]], 1)
	return ans

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

def nb(i, j, n, m):
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j - 1], [i, j + 1]]:
		if 0 <= ni < n and 0 <= nj < m:
			yield (ni, nj)

def topo(n):
	q = deque()
	res = []
	for i in range(1, n + 1):
		if ind[i] == 0:
			q.append(i)
			res.append(i)
	while q:
		u = q.popleft()
		for v in g[u]:
			ind[v] -= 1
			if ind[v] == 0:
				q.append(v)
				res.append(v)
	return res

@bootstrap
def gdfs(r, p):
	for ch in g[r]:
		if ch != p:
			yield gdfs(ch, r)
	yield None
t = N()
for i in range(t):
	(n, c) = RL()
	a = RLL()
	b = RLL()
	p = A(n)
	rem = A(n)
	ans = (c + a[0] - 1) // a[0]
	for i in range(1, n):
		if rem[i - 1] >= b[i - 1]:
			p[i] = p[i - 1] + 1
			rem[i] = rem[i - 1] - b[i - 1]
		else:
			need = (b[i - 1] - rem[i - 1] + a[i - 1] - 1) // a[i - 1]
			p[i] = p[i - 1] + need + 1
			rem[i] = rem[i - 1] + need * a[i - 1] - b[i - 1]
		if rem[i] >= c:
			cur = p[i]
		else:
			cur = p[i] + (c - rem[i] + a[i] - 1) // a[i]
		ans = min(ans, cur)
	print(ans)


from math import *
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	d = 0
	b = 0
	out = 10 ** 9
	for i in range(n - 1):
		out = min(out, ceil(max(0, c - b) / arr[i]) + d)
		if brr[i] - b > 0:
			d += ceil((brr[i] - b) / arr[i])
			b += ceil((brr[i] - b) / arr[i]) * arr[i]
		d += 1
		b -= brr[i]
	out = min(out, ceil(max(0, c - b) / arr[-1]) + d)
	print(out)


import math
for _ in range(int(input())):
	(n, c) = input().split()
	n = int(n)
	c = int(c)
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = list()
	temp = math.ceil(b[0] / a[0])
	remain = a[0] * math.ceil(b[0] / a[0]) - b[0]
	ans.append(math.ceil(c / a[0]))
	for i in range(1, n - 1):
		ans.append(math.ceil((c - remain) / a[i]) + temp + 1)
		temp += math.ceil((b[i] - remain) / a[i]) + 1
		remain = a[i] * math.ceil((b[i] - remain) / a[i]) - b[i] + remain
	temp += math.ceil((c - remain) / a[-1]) + 1
	print(min(min(ans), temp))


times = int(input())
while times > 0:
	times -= 1
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cnt = 0
	now = 0
	ans = (c + a[0] - 1) // a[0]
	for i in range(1, n):
		if now >= c:
			break
		t = (b[i - 1] - now + a[i - 1] - 1) // a[i - 1]
		now += t * a[i - 1] - b[i - 1]
		cnt += t + 1
		tmp = (c - now + a[i] - 1) // a[i] + cnt
		ans = min(ans, tmp)
	print(ans)


import sys
import math
import bisect
import functools
from functools import lru_cache
from sys import stdin, stdout
from math import gcd, floor, sqrt, log, ceil
from heapq import heappush, heappop, heapify
from collections import defaultdict as dd
from collections import Counter as cc
from bisect import bisect_left as bl
from bisect import bisect_right as br
import collections

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)
sys.setrecursionlimit(100000000)
intinp = lambda : int(input().strip())
stripinp = lambda : input().strip()
fltarr = lambda : list(map(float, input().strip().split()))
intarr = lambda : list(map(int, input().strip().split()))
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
MOD = 1000000007
num_cases = intinp()
for _ in range(num_cases):
	(n, c) = intarr()
	A = intarr()
	B = intarr()
	mn = 1e309
	has = 0
	days = 0
	for i in range(n - 1):
		finish = math.ceil((c - has) / A[i])
		mn = min(finish + days, mn)
		upgrade = math.ceil((B[i] - has) / A[i])
		if upgrade > 0:
			days += upgrade
			has += upgrade * A[i]
		days += 1
		has -= B[i]
	finish = math.ceil((c - has) / A[-1])
	mn = min(finish + days, mn)
	print(mn)


import sys
input = sys.stdin.readline
output = sys.stdout.write

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 ceil(n, d):
	if n % d == 0:
		return n // d
	else:
		return 1 + n // d

def main():
	t = inp()
	for i in range(0, t):
		[n, c] = inlt()
		solve(n, c, inlt(), inlt())

def req_days(arv_asset, earn, cost):
	rem = max(0, cost - arv_asset)
	return ceil(rem, earn)

def solve(n, c, a, b):
	arv_day = [0 for i in range(0, n)]
	arv_asset = [0 for i in range(0, n)]
	for i in range(0, n - 1):
		clct_days = ceil(max(0, b[i] - arv_asset[i]), a[i])
		arv_day[i + 1] = arv_day[i] + clct_days + 1
		arv_asset[i + 1] = arv_asset[i] + clct_days * a[i] - b[i]
	min_days = req_days(0, a[0], c)
	for i in range(1, n):
		min_days = min(min_days, arv_day[i] + req_days(arv_asset[i], a[i], c))
	output('{}\n'.format(min_days))
main()


import sys
ints = (int(x) for x in sys.stdin.read().split())
sys.setrecursionlimit(3000)

def main():
	ntc = next(ints)
	for tc in range(1, ntc + 1):
		(n, c) = (next(ints) for i in range(2))
		a = [next(ints) for i in range(n)]
		b = [next(ints) for i in range(n - 1)]

		def ceil(num, den):
			return (num + den - 1) // den
		i = 0
		m = 0
		days = 0
		ans = float('inf')
		while 1:
			ans = min(ans, days + ceil(c - m, a[i]))
			if i == n - 1:
				break
			k = ceil(max(0, b[i] - m), a[i])
			m += a[i] * k - b[i]
			assert m >= 0
			days += k + 1
			i += 1
		print(ans)
	return
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')
for case in range(int(input())):
	(n, c) = map(int, input().split())
	(a, b) = ([*map(int, input().split())], [*map(int, input().split())])
	days_dp = [-1] * n
	days_dp[0] = 0
	balance_dp = [-1] * n
	balance_dp[0] = 0
	ans = [0] * n
	for i in range(n):
		balance = balance_dp[i]
		days_to_buy = (c - balance + a[i] - 1) // a[i]
		ans[i] = days_dp[i] + days_to_buy
		if i != n - 1:
			days_to_progress = (b[i] - balance + a[i] - 1) // a[i]
			days_dp[i + 1] = days_dp[i] + days_to_progress + 1
			balance_dp[i + 1] = balance + days_to_progress * a[i] - b[i]
	print(min(ans))


from math import inf, ceil
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, cost) = map(int, input().split())
	earnings = list(map(int, input().split()))
	progress_cost = list(map(int, input().split()))
	minimum_cost = inf
	day = 0
	has_money = 0
	for i in range(n - 1):
		minimum_cost = min(minimum_cost, day + ceil((cost - has_money) / earnings[i]))
		days_on_position = ceil((progress_cost[i] - has_money) / earnings[i])
		day += days_on_position + 1
		has_money += days_on_position * earnings[i] - progress_cost[i]
	minimum_cost = min(minimum_cost, day + ceil((cost - has_money) / earnings[-1]))
	print(minimum_cost)


import sys
max_int = 10 ** 18

def ceil(p, q):
	return (p - 1) // q + 1
t = int(input())
for _t in range(t):
	(n, c) = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split())) + [0]
	for i in range(1, len(a)):
		a[i] = max(a[i], a[i - 1])
	out = max_int
	d = 0
	cash = 0
	for i in range(len(a)):
		out = min(out, d + max(0, ceil(c - cash, a[i])))
		days_to_up = max(ceil(b[i] - cash, a[i]), 0)
		d += days_to_up + 1
		cash = cash - b[i] + days_to_up * a[i]
	print(out)


import sys
import math
import collections
input = sys.stdin.readline
t = int(input())
for w in range(t):
	(n, c) = (int(i) for i in input().split())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	l = []
	reach = 0
	r = []
	s = 0
	for i in range(n - 1):
		c1 = a[i]
		l.append(reach + max(0, math.ceil((c - s) / c1)))
		reach += math.ceil((b[i] - s) / c1) + 1
		r.append(reach)
		s += max(0, math.ceil((b[i] - s) / c1) * c1) - b[i]
	l.append(reach + max(0, math.ceil((c - s) / a[n - 1])))
	print(min(l))


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

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

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

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

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

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	(n, k) = mp()
	a = li()
	b = li()
	b.append(0)
	ans = INF
	total = 0
	day = 0
	for i in range(n):
		if total >= k:
			pr(ans)
			return
		if i == n - 1:
			p = k - total
			h = (p + a[i] - 1) // a[i]
			ans = min(ans, day + h)
		else:
			p = k - total
			h = (p + a[i] - 1) // a[i]
			ans = min(ans, day + h)
			if total >= b[i]:
				day += 1
				total -= b[i]
			else:
				u = (b[i] - total + a[i] - 1) // a[i]
				day += u + 1
				total = total + a[i] * u - b[i]
	pr(ans)
for _ in range(inp()):
	solve()


import math
from sys import stdin, stdout
input = stdin.readline
for t in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	days = 0
	money = 0
	dp = [(0, 0)]
	for i in range(n - 1):
		if money < b[i]:
			temp = math.ceil((b[i] - money) / a[i])
			days += temp
			money += temp * a[i]
		money -= b[i]
		days += 1
		dp.append((money, days))
	min_days = -1
	for i in range(n):
		money = dp[i][0]
		days = dp[i][1]
		ans = days + math.ceil((c - money) / a[i])
		if min_days == -1:
			min_days = ans
		else:
			min_days = min(min_days, ans)
	print(min_days)


import sys
input = sys.stdin.readline
ceil = lambda x, y: (x + y - 1) // y
t = int(input())
for _ in range(t):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ans = ceil(c, a[0])
	switch = [0]
	balance = [0]
	for i in range(1, n):
		switch.append(1 + switch[i - 1] + ceil(b[i - 1] - balance[i - 1], a[i - 1]))
		balance.append(balance[i - 1] + (switch[i] - switch[i - 1] - 1) * a[i - 1] - b[i - 1])
		ans = min(ans, switch[i] + ceil(c - balance[i], a[i]))
	print(ans)


from math import ceil
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	b.append(0)
	ans = 1e+18
	cur_money = 0
	spend_days = 0
	for i in range(n):
		ans = min(ans, spend_days + ceil(max(0, c - cur_money) / a[i]))
		days_for_upgrade = ceil(max(0, b[i] - cur_money) / a[i])
		spend_days += days_for_upgrade + 1
		cur_money = cur_money + days_for_upgrade * a[i] - b[i]
	print(ans)


from math import ceil

def f(arr, b, c):
	b.append(0)
	currd = 0
	currm = 0
	ans = float('inf')
	j = 0
	for i in arr:
		ans = min(ans, max(ceil((c - currm) / i), 0) + currd)
		t = max(ceil((b[j] - currm) / i), 0)
		currd += t + 1
		currm += t * i - b[j]
		j += 1
	return ans
for i in range(int(input())):
	(a, b) = map(int, input().strip().split())
	lst = list(map(int, input().strip().split()))
	lst2 = list(map(int, input().strip().split()))
	print(f(lst, lst2, b))


import collections

def permutationbysum():
	for _ in range(int(input())):
		(num, l, r, achieve) = map(int, input().split())
		k = r - l + 1
		if k * (k + 1) // 2 <= achieve <= k * (num * 2 + 1 - k) // 2:
			outpos = r % num
			inpos = l - 1
			ans = [0] * num
			for i in range(num, 0, -1):
				if achieve - i > 0 or (achieve - i == 0 and inpos == r - 1):
					achieve -= i
					ans[inpos] = i
					inpos += 1
				else:
					ans[outpos] = i
					outpos += 1
					outpos %= num
			print(*ans)
		else:
			print(-1)

def peaks():
	for _ in range(int(input())):
		(num, peak) = map(int, input().split())
		pos = 1
		rpos = num
		ans = []
		now = 0
		if num == 1:
			if not peak:
				print(1)
			else:
				print(-1)
			continue
		if num == 2:
			if peak:
				print(-1)
			else:
				print(1, 2)
			continue
		added = 0
		while rpos + 1 != pos:
			if not peak:
				while pos <= rpos:
					ans.append(pos)
					pos += 1
				break
			if not now:
				ans.append(pos)
				pos += 1
			else:
				ans.append(rpos)
				rpos -= 1
				if num - added != 1:
					peak -= 1
			added += 1
			now = 1 - now
		if peak:
			print(-1)
			continue
		print(*ans)
import sys
input = sys.stdin.readline

def addone():
	for _ in range(int(input())):
		(num, changes) = input().split()
		l = collections.deque(sorted([int(i) for i in num]))
		perm = collections.deque()
		changes = int(changes)
		cd = 0
		ans = len(num)
		while True:
			nextnum = l.pop()
			while perm and perm[-1] == nextnum:
				l.append(perm.pop())
			c = 10 - nextnum - cd
			changes -= c
			cd += c
			if changes >= 0:
				if not c:
					perm.appendleft(1 - cd)
					l.appendleft(-cd)
				else:
					l.appendleft(1 - cd)
					l.appendleft(-cd)
				ans += 1
			else:
				break
		print(ans % 1000000007)
import math

def andsequences():

	def mapping(num):
		nonlocal mnum
		nonlocal c
		num = int(num)
		if num < mnum:
			mnum = num
			c = 1
		elif num == mnum:
			c += 1
		return num
	mod = 1000000007
	for _ in range(int(input())):
		mnum = float('inf')
		c = 0
		num = int(input())
		l = list(map(mapping, input().split()))
		for i in l:
			if mnum & i != mnum:
				print(0)
				break
		else:
			if c == 1:
				print(0)
			else:
				print(math.factorial(num - 2) * (c - 1) * c % mod)

def numberdigit():
	n = 10 ** 5 * 2
	l = [0] * 11
	mod = 10 ** 9 + 7
	l[0] = l[1] = l[2] = l[3] = l[4] = l[5] = l[6] = l[7] = l[8] = 2
	l[9] = 3
	l[10] = 4
	for i in range(11, n):
		l.append((l[i - 10] + l[i - 9]) % mod)
	for _ in range(int(input())):
		(num, c) = input().split()
		c = int(c)
		ans = 0
		for i in num:
			i = int(i)
			if 10 - i > c:
				ans += 1
			else:
				ans += l[c - (10 - i)]
		print(ans % mod)

def mushroom():
	(people, t1, t2, percent) = map(int, input().split())
	l = []
	percent = 1 - percent * 0.01
	for i in range(1, people + 1):
		(s, s1) = map(int, input().split())
		l.append([i, max(s * t1 * percent + s1 * t2, s1 * t1 * percent + s * t2)])
	l.sort(key=lambda x: x[1], reverse=True)
	for i in l:
		i[1] = '{:.2f}'.format(i[1])
		print(*i)

def escape():
	prins = int(input())
	dra = int(input())
	start = int(input())
	pack = int(input())
	c = int(input())
	speeddiff = dra - prins
	if speeddiff <= 0:
		return 0
	pd = start * prins
	ans = 0
	while pd < c:
		hs = pd / speeddiff
		pd += prins * hs
		if pd >= c:
			break
		time = pd / dra
		time += pack
		pd += prins * time
		ans += 1
	return ans

def perm():

	def high(n, k):
		return k * (2 * n - k + 1) // 2

	def low(k):
		return k * (k + 1) // 2
	for _ in range(int(input())):
		(num, lef, rig, s) = map(int, input().split())
		k = rig - lef + 1
		(rig, lef) = (rig - 1, lef - 1)
		if not high(num, k) >= s >= low(k):
			print(-1)
			continue
		l = [0] * num
		lp = lef
		rp = lef - 1
		for i in range(num, 0, -1):
			if high(i, k) >= s and s - i >= low(k - 1) and k:
				l[lp] = i
				lp += 1
				s -= i
				k -= 1
			else:
				l[rp] = i
				rp -= 1
		if k:
			print(-1)
		else:
			print(*l)

def newcom():
	for _ in range(int(input())):
		(days, price) = map(int, input().split())
		dl = input().split()
		worth = input().split()
		worth.append(0)
		ans = float('inf')
		req = 0
		left = 0
		for i in range(days):
			a = int(dl[i])
			w = int(worth[i])
			ans = min(ans, req + max(0, price - left + a - 1) // a)
			ns = max(0, w - left + a - 1) // a
			req += ns + 1
			left += a * ns - w
		print(ans)
newcom()


from sys import stdin, stdout
import math

def education(n, c, a_a, b_a):
	r = 2 ** 63 - 1
	m = 0
	d = 0
	for i in range(n):
		if m > c:
			r = min(r, d)
		else:
			r = min(r, d + math.ceil((c - m) / a_a[i]))
		if i < n - 1:
			if b_a[i] > m:
				ld = math.ceil((b_a[i] - m) / a_a[i])
				d += ld + 1
				m += ld * a_a[i] - b_a[i]
			else:
				m -= b_a[i]
				d += 1
	return r
t = int(stdin.readline())
for _ in range(t):
	(n, c) = map(int, stdin.readline().split())
	a_a = list(map(int, stdin.readline().split()))
	b_a = list(map(int, stdin.readline().split()))
	r = education(n, c, a_a, b_a)
	stdout.write(str(r) + '\n')


import bisect
import collections
import functools
import itertools
import math
import heapq
import random
import string

def repeat(_func=None, *, times=1):

	def decorator(func):

		@functools.wraps(func)
		def wrapper(*args, **kwargs):
			for _ in range(times):
				func(*args, **kwargs)
		return wrapper
	if _func is None:
		return decorator
	else:
		return decorator(_func)

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def getint():
	return int(input())

def getmatrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def display_matrix(mat):
	for i in range(len(mat)):
		print(mat[i])

@repeat(times=int(input()))
def main():
	(n, c) = unpack()
	salary = l_unpack()
	course = l_unpack()
	money = days_spent = 0
	mdays = float('inf')
	for i in range(n):
		days_spent += 1
		d = mceil((c - money) / salary[i])
		mdays = min(mdays, d + days_spent)
		if i == n - 1:
			break
		if money >= course[i]:
			money -= course[i]
			continue
		d = mceil((course[i] - money) / salary[i])
		days_spent += d
		money = money + d * salary[i] - course[i]
	print(mdays - 1)
mceil = math.ceil
MOD = 10 ** 9 + 7
main()


import math

def solve(a, b, n, m):
	time = [0] * n
	ost = [0] * n
	for i in range(1, n):
		time_on_current_curs = max(math.ceil((b[i - 1] - ost[i - 1]) / a[i - 1]), 0)
		time[i] = time[i - 1] + time_on_current_curs + 1
		ost[i] = time_on_current_curs * a[i - 1] - (b[i - 1] - ost[i - 1])
	return min((max(math.ceil((m - ost[i]) / a[i]), 0) + time[i] for i in range(n)))
for _ in range(int(input())):
	(n, m) = [int(token) for token in input().split()]
	a = [int(token) for token in input().split()]
	b = [int(token) for token in input().split()]
	print(solve(a, b, n, m))


import time, math as mt, bisect as bs, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IP():
	return map(int, stdin.readline().split())

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

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

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

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def readTree(n, e):
	adj = [set() for i in range(n + 1)]
	for i in range(e):
		(u1, u2) = IP()
		adj[u1].add(u2)
	return adj

def sieve():
	li = [True] * (10 ** 3 + 5)
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	(prime, cur) = ([0] * 200, 0)
	for i in range(10 ** 3 + 5):
		if li[i] == True:
			prime[cur] = i
			cur += 1
	return prime

def SPF():
	mx = 10 ** 7 + 1
	spf = [mx] * mx
	spf[1] = 1
	for i in range(2, mx):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx, i):
				if i < spf[j]:
					spf[j] = i
	return spf

def prime(n, d):
	while n != 1:
		d[spf[n]] = d.get(spf[n], 0) + 1
		n = n // spf[n]
	return
mod = 998244353
inf = 10000000000000000

def solve():
	(n, c) = IP()
	a = L()
	b = L()
	ans = inf
	days = 0
	money = 0
	for i in range(n):
		if c > money or i == n - 1:
			num = (c + a[i] - money - 1) // a[i]
			ans = min(ans, num + days)
		else:
			ans = min(ans, days)
		if i != n - 1:
			if b[i] > money:
				promoted = (b[i] + a[i] - money - 1) // a[i]
				money += a[i] * promoted
				money -= b[i]
				days += promoted + 1
			else:
				money -= b[i]
				days += 1
	print(ans)
	return
t = II()
for i in range(t):
	solve()


def solve():
	lst = input().split()
	n = int(lst[0])
	c = int(lst[1])
	a = list(map(lambda x: int(x), input().split()))
	b = list(map(lambda x: int(x), input().split()))
	mint = [0] * n
	extr = [0] * n
	for i in range(0, n - 1):
		delned = b[i] - extr[i]
		tiempo = (delned + a[i] - 1) // a[i]
		delned -= tiempo * a[i]
		mint[i + 1] = mint[i] + tiempo + 1
		extr[i + 1] = -delned
	minn = -1
	for i in range(n):
		aans = (c - extr[i] + a[i] - 1) // a[i]
		if minn == -1:
			minn = aans
		minn = min(minn, aans + mint[i])
	print(minn)
caso = int(input())
while caso > 0:
	caso -= 1
	solve()


def debug(*args):
	pass
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	(*salaries,) = map(int, input().split())
	(*prices,) = map(int, input().split())
	days_to_reach = [0]
	rem = [0]
	balance = 0
	for i in range(n - 1):
		days = (prices[i] - balance + salaries[i] - 1) // salaries[i]
		balance += days * salaries[i] - prices[i]
		rem.append(balance)
		days_to_reach.append(days + 1)
	cum_days_to_reach = days_to_reach.copy()
	for i in range(n - 1):
		cum_days_to_reach[i + 1] += cum_days_to_reach[i]
	ans = (c + salaries[0] - 1) // salaries[0]
	debug('rem', rem)
	debug('days_to_reach', days_to_reach)
	debug('cum_days', cum_days_to_reach)
	debug(ans)
	for i in range(1, n):
		new_ans = cum_days_to_reach[i] + (c - rem[i] + salaries[i] - 1) // salaries[i]
		if new_ans < ans:
			ans = new_ans
			debug(i, 'is better', new_ans)
	print(ans)


def solve():
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	cur_money = 0
	cur_days = 0
	ans = int(1000000000000.0)
	for i in range(n):
		need_to_buy = c - cur_money
		ans = min(ans, cur_days + (need_to_buy + a[i] - 1) // a[i])
		if i < n - 1:
			need_to_upgrade = b[i] - cur_money
			if need_to_upgrade <= 0:
				cur_days += 1
				cur_money -= b[i]
			else:
				cur_days += (need_to_upgrade + a[i] - 1) // a[i]
				cur_days += 1
				cur_money = (need_to_upgrade + a[i] - 1) // a[i] * a[i] - need_to_upgrade
	print(ans)
for _ in range(int(input())):
	solve()


import sys
from math import ceil
input = sys.stdin.readline
for _ in range(int(input())):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	money = days = 0
	ans = float('inf')
	for i in range(len(a)):
		ans = min(ans, days + ceil((c - money) / a[i]))
		if i == len(b):
			break
		dnta = ceil((b[i] - money) / a[i])
		money += dnta * a[i] - b[i]
		days += dnta + 1
	print(ans)


import sys
input = sys.stdin.readline
for CASES in range(int(input())):
	(n, c) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	ans = 10 ** 9
	last = 0
	now = 0
	top = 0
	i = 0
	while top != n - 1:
		if last >= B[top]:
			last -= B[top]
			top += 1
			i += 1
		delta = c - last
		addi = (delta + A[top] - 1) // A[top]
		ans = min(ans, i + addi)
		if top == n - 1:
			break
		i += (B[top] - last + A[top] - 1) // A[top]
		last += (B[top] - last + A[top] - 1) // A[top] * A[top]
	print(ans)


import math
for t in range(int(input())):
	(n, c) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	b.append(0)
	days = 10 ** 10
	dol = 0
	k = 0
	for i in range(n):
		if dol >= c:
			days = min(days, k)
		else:
			days = min(days, k + int(math.ceil((c - dol) / a[i])))
		if dol >= b[i]:
			dol -= b[i]
			k += 1
		else:
			k += 1 + int(math.ceil((b[i] - dol) / a[i]))
			dol = int(math.ceil((b[i] - dol) / a[i])) * a[i] - (b[i] - dol)
	print(days)


def solve(n, c, a, b):
	res = c
	money = 0
	days = 0
	for i in range(n):
		res = min(res, days + (c - money + a[i] - 1) // a[i])
		if i + 1 < n:
			extra_days = (max(b[i] - money, 0) + a[i] - 1) // a[i]
			money += a[i] * extra_days
			money -= b[i]
			assert money >= 0
			days += extra_days
			days += 1
	return res
t = int(input())
for _ in range(t):
	(n, c) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	print(solve(n, c, a, b))