The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of $n$ haybale piles on the farm. The $i$-th pile contains $a_i$ haybales. 

However, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, Bessie the naughty cow can choose to move one haybale in any pile to an adjacent pile. Formally, in one day she can choose any two indices $i$ and $j$ ($1 \le i, j \le n$) such that $|i-j|=1$ and $a_i>0$ and apply $a_i = a_i - 1$, $a_j = a_j + 1$. She may also decide to not do anything on some days because she is lazy.

Bessie wants to maximize the number of haybales in pile $1$ (i.e. to maximize $a_1$), and she only has $d$ days to do so before Farmer John returns. Help her find the maximum number of haybales that may be in pile $1$ if she acts optimally!


-----Input-----

The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 100$)  — the number of test cases. Next $2t$ lines contain a description of test cases  — two lines per test case.

The first line of each test case contains integers $n$ and $d$ ($1 \le n,d \le 100$) — the number of haybale piles and the number of days, respectively. 

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 100$)  — the number of haybales in each pile.


-----Output-----

For each test case, output one integer: the maximum number of haybales that may be in pile $1$ after $d$ days if Bessie acts optimally.


-----Example-----
Input
3
4 5
1 0 3 2
2 2
100 1
1 8
0

Output
3
101
0



-----Note-----

In the first test case of the sample, this is one possible way Bessie can end up with $3$ haybales in pile $1$:   On day one, move a haybale from pile $3$ to pile $2$  On day two, move a haybale from pile $3$ to pile $2$  On day three, move a haybale from pile $2$ to pile $1$  On day four, move a haybale from pile $2$ to pile $1$  On day five, do nothing  

In the second test case of the sample, Bessie can do nothing on the first day and move a haybale from pile $2$ to pile $1$ on the second day.

Source: codeforces | Difficulty: EASY
Tags: Implementation

Greedy algorithms


Solutions:
t = int(input())
for _ in range(t):
	(n, now) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = a[0]
	for i in range(1, n):
		tmp = min(now // i, a[i])
		ans += tmp
		now -= tmp * i
	print(ans)


t = int(input())
for j in range(t):
	(n, d) = map(int, input().split())
	h = list(map(int, input().split()))
	s = h[0]
	for i in range(1, n):
		if d < i:
			break
		elif i * h[i] < d:
			s += h[i]
			d -= i * h[i]
		else:
			while i * h[i] > d:
				h[i] -= 1
			s += h[i]
			break
	print(s)


for _ in range(int(input())):
	(n, d) = (int(x) for x in input().strip().split(' '))
	L = [int(x) for x in input().strip().split(' ')]
	ans = L[0]
	for i in range(1, len(L)):
		can = min(d // i, L[i])
		d = max(0, d - can * i)
		ans += can
	print(ans)


t = int(input())
Matrixnd = [[-1] * 2 for i in range(t)]
Matrix = [[-1] * 100 for i in range(t)]
for i in range(t):
	k = list(map(int, input().split()))
	Matrixnd[i] = k
	k = list(map(int, input().split()))
	Matrix[i] = k
for i in range(t):
	z = 0
	st = Matrix[i][0]
	n = Matrixnd[i][0]
	d = Matrixnd[i][1]
	for j in range(1, Matrixnd[i][0]):
		while Matrix[i][j] != 0:
			if d - j >= 0:
				d -= j
				st += 1
				Matrix[i][j] -= 1
			else:
				z = 1
				print(st)
				break
		if z == 1:
			break
	if z == 0:
		print(st)


for tests in range(int(input())):
	(N, D) = map(int, input().split())
	P = list(map(int, input().split()))
	for i in range(1, N):
		if i > D:
			break
		if P[i] > 0:
			dP = i
			if dP > D:
				break
			else:
				k = D // dP
				if k <= P[i]:
					D -= k * dP
					P[0] += k
					break
				else:
					D -= P[i] * dP
					P[0] += P[i]
	print(P[0])


def budgetedMove(budget, cost, number):
	if budget == 0 or budget < cost or number == 0:
		return (budget, 0)
	if number > 0:
		ns = list(range(number + 1))
		ns.reverse()
		for n in ns:
			if budget >= n * cost:
				return (budget - n * cost, n)

def main():
	testcases = int(input())
	for t in range(testcases):
		i_s = input()
		(n_piles, days) = [int(i) for i in i_s.split(' ')]
		piles = [int(i) for i in input().split(' ')]
		n_total = piles[0]
		for i in range(len(piles)):
			if i == 0:
				continue
			[days, inc] = budgetedMove(days, i, piles[i])
			n_total += inc
		print(n_total)
main()


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 1
	if len(a) == 1:
		print(a[0])
		continue
	while d >= 0 and i < n:
		while a[i] != 0:
			if d - i < 0:
				break
			a[i] = a[i] - 1
			a[0] += 1
			d = d - i
		i += 1
	print(a[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	t = 0
	r = 0
	k = 0
	if n == 1:
		print(a[0])
	else:
		for i in range(1, n):
			t = t + a[i] * i
			if t > d:
				r = i
				k += 1
				break
		if k > 0:
			t = t - a[r] * r
			n = (d - t) // r
			print(sum(a[:r]) + n)
		else:
			print(sum(a))


t = int(input())
for u in range(t):
	(n, d) = map(int, input().split())
	A = list(map(int, input().split()))
	for i in range(1, n):
		if d < i:
			break
		tmp = min(d // i, A[i])
		A[0] += tmp
		d -= tmp * i
	print(A[0])


for _ in range(int(input())):
	(n, d) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	ans = a[0]
	for i in range(1, n):
		if a[i] != 0 and d >= i:
			ans += min(d // i, a[i])
			d -= min(d // i, a[i]) * i
	print(ans)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = [int(j) for j in input().split()]
	ans = a[0]
	for i in range(1, n):
		if d > i * a[i]:
			d -= i * a[i]
			ans += a[i]
		else:
			ans += d // i
			break
	print(ans)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(d):
		for i in range(1, n):
			if l[i] > 0:
				l[i - 1] += 1
				l[i] -= 1
				break
	print(l[0])


t = int(input())
for _ in range(t):
	hello = list(map(int, input().split()))
	n = hello[0]
	d = hello[1]
	hay = list(map(int, input().split()))
	for i in range(1, n):
		move = min(d // i, hay[i])
		hay[0] += move
		d -= move * i
	print(hay[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	j = 1
	while j < n and d > 0:
		if d >= j * a[j]:
			d -= j * a[j]
			a[0] += a[j]
		else:
			a[0] += d // j
			d -= j * (d // j)
		j += 1
	print(a[0])


t = int(input())
for tt in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 1
	while d >= i and i < n:
		if a[i] > 0:
			a[i] -= 1
			a[0] += 1
			d -= i
		while i < n and a[i] == 0:
			i += 1
	print(a[0])


t = int(input())
for te in range(t):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(1, n):
		if d // i >= arr[i]:
			arr[0] += arr[i]
			d = d - arr[i] * i
		else:
			arr[0] += d // i
			d -= d // i * i
	print(arr[0])


t = int(input())
while t > 0:
	(n, d) = map(int, input().split())
	a = [int(s) for s in input().split()]
	x = d
	s = 0
	for i in range(1, n):
		if d > i * a[i]:
			s += a[i]
			d -= i * a[i]
		else:
			s += d // i
			break
	s += a[0]
	print(s)
	t -= 1


testcases = int(input())
for testcase in range(testcases):
	getInput = str(input())
	getInput = getInput.split()
	piles = int(getInput[0])
	days = int(getInput[1])
	arr = []
	getInput = str(input())
	getInput = getInput.split()
	count = 0
	for i in range(piles):
		arr.append(int(getInput[i]))
	times = 1
	for i in range(piles):
		if days <= 0:
			break
		if i == 0:
			continue
		if arr[i] == 0:
			times += 1
			continue
		number = arr[i] * times
		if days >= number:
			days -= number
			count += arr[i]
		else:
			count += days // times
			break
		times += 1
	print(count + arr[0])


import math
t = int(input())
while t != 0:
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(1, n):
		if a[i] != 0:
			if i * a[i] <= d:
				a[0] = a[0] + a[i]
				d = d - a[i] * i
				a[i] = 0
			else:
				temp = math.floor(d / i)
				a[0] = a[0] + temp
				break
	print(a[0])
	t = t - 1


for k in range(int(input())):
	(n, d) = map(int, input().split())
	hay = list(map(int, input().split()))
	d1 = 0
	d2 = 0
	h1 = 0
	h = 0
	for i in range(n):
		d1 += i * hay[i]
		if d1 > d:
			h = (d - d2) // i
			break
		else:
			h1 += hay[i]
		d2 = d1
	print(h + h1)


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


num_cases = int(input())

def move_hay(list_obj):
	if len(list_obj) <= 1:
		return list_obj
	else:
		index = 1
		while index < len(list_obj):
			if list_obj[index] <= 0:
				index += 1
			else:
				break
		if index == len(list_obj):
			return list_obj
		else:
			list_obj[index] -= 1
			list_obj[index - 1] += 1
			return list_obj
for i in range(num_cases):
	nums = list(map(int, input().split()))
	hay_bales = list()
	while len(hay_bales) != nums[0]:
		hay_bales.extend(list(map(int, input().split())))
	for j in range(nums[1]):
		hay_bales = move_hay(hay_bales)
	print(hay_bales[0])


t = int(input())
for test in range(t):
	(n, d) = [int(x) for x in input().split()]
	bales = [int(x) for x in input().split()]
	for i in range(1, n):
		if d == 0:
			break
		if d - i * bales[i] >= 0:
			d -= i * bales[i]
			bales[0] += bales[i]
		else:
			c = d // i
			bales[0] += c
			break
	print(bales[0])


inputNum = int(input())
ansList = []
for i in range(inputNum):
	(pile, day) = map(int, input().split())
	pileList = [int(n) for n in input().split()]
	dayCount = 0
	ans = 0
	for j in range(pile):
		check = True
		while pileList[j] > 0:
			if dayCount + j <= day:
				dayCount += j
				ans += 1
				pileList[j] -= 1
			else:
				check = False
				break
		if check == False or j == len(pileList) - 1:
			ansList.append(ans)
			break
for i in ansList:
	print(i)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(1, n):
		if a[i] == 0:
			continue
		c = d // (i * a[i])
		if c == 0:
			a[0] += d // i
			break
		else:
			a[0] += a[i]
		d -= i * a[i]
	print(a[0])


import sys
input = sys.stdin.readline
mii = lambda : list(map(int, input().split()))
for _ in range(int(input())):
	(n, d) = mii()
	a = list(mii())
	ans = 0
	for i in range(n):
		while d >= i and a[i]:
			a[i] -= 1
			ans += 1
			d -= i
	print(ans)


import sys
import math
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
for _ in range(int(input())):
	(n, d) = read()
	a = read()
	for i in range(1, n):
		m = min(d // i, a[i])
		a[0] += m
		d -= m * i
	print(a[0])


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	d = int(l[1])
	l = input().split()
	li = [int(i) for i in l]
	ans = 0
	for i in range(n):
		if i * li[i] > d:
			ans = ans + d // i
			break
		else:
			ans = ans + li[i]
			d = d - i * li[i]
	print(ans)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = [int(i) for i in input().split()]
	i = 1
	j = 0
	while i < n and j < d:
		if i == 0:
			i += 1
		while i < n and a[i] < 1:
			i += 1
		if i < n:
			a[i] -= 1
			a[i - 1] += 1
			j += 1
			i -= 1
	print(a[0])


for nt in range(int(input())):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = 0
	for i in range(1, n):
		if l[i] * i <= d:
			ans += l[i]
			d -= l[i] * i
		else:
			ans += d // i
			break
	print(ans + l[0])


m = int(input())
for i in range(m):
	(a, b) = input().split()
	f = int(b)
	c = list(map(int, input().split()))
	for j in range(1, int(a)):
		e = min(c[j], f // j)
		c[0] += e
		f -= e * j
	print(c[0])


t = int(input())
for _ in range(t):
	(piles, days) = [int(i) for i in input().split()]
	bales = [int(i) for i in input().split()]
	bales_in_1 = 0
	for p in range(piles):
		_days = bales[p] * p
		if days >= _days:
			days -= _days
			bales_in_1 += bales[p]
		else:
			bales_in_1 += days // p
			break
	print(bales_in_1)


x = int(input())
for i in range(x):
	(x, y) = list(map(int, input().split()))
	if x >= 1 and x <= 100 and (y >= 1) and (y <= 100):
		a = list(map(int, input().split()))
		for i in range(y):
			if x == 0 and y == 0:
				print(0)
				break
			if x == 1 or y == 0:
				print(a[0])
				break
			if x == 0:
				print(0)
				break
			for j in range(1, x):
				if a[j] > 0:
					a[j] = a[j] - 1
					a[j - 1] = a[j - 1] + 1
					break
			if i == y - 1:
				print(a[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	sum = 0
	haybales = list(map(int, input().split()))
	for i in range(n):
		res = haybales[i]
		if res * i <= d:
			sum += res
			d -= res * i
		else:
			res2 = d // i
			sum += res2
			break
	print(sum)


t = int(input())
f = []
for i in range(t):
	q = [int(i) for i in input().split()]
	(g, d) = (q[0], q[-1])
	a = [int(i) for i in input().split()]
	j = 1
	n = 0
	while n < d and j != len(a):
		n += j * a[j]
		a[0] += a[j]
		j += 1
	if n > d and j <= len(a):
		x = (d - (n - (j - 1) * a[j - 1])) // (j - 1) + a[0] - a[j - 1]
		f.append(x)
	else:
		f.append(a[0])
for i in f:
	print(i)


for i in range(int(input())):
	(stogs, day) = input().split()
	tuks = input().split(' ')
	for j in range(int(stogs)):
		tuks[j] = int(tuks[j])
	for j in range(int(day)):
		for k in range(int(stogs) - 1):
			if tuks[k + 1] != 0:
				tuks[k] += 1
				tuks[k + 1] -= 1
				break
	print(tuks[0])


def main():
	t = int(input())
	arr = []
	while t != 0:
		(n, d) = [int(x) for x in input().split()]
		arr = list(map(int, input().split()))
		i = 1
		sum = arr[0]
		for i in range(1, n):
			if d / i > 0:
				sum = sum + int(min(arr[i], d / i))
				d = d - i * int(min(arr[i], d / i))
			else:
				break
		print(sum)
		t = t - 1
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')
import bisect
for j in range(int(input())):
	(n, d) = map(int, input().split())
	vals = list(map(int, input().split()))
	for s in range(d):
		for b in range(1, n):
			if vals[b] > 0:
				vals[b - 1] += 1
				vals[b] -= 1
				break
	print(vals[0])


t = int(input())
s = []
for jnnj in range(0, t):
	x = input()
	xx = x.split()
	n = int(xx[0])
	d = int(xx[1])
	x = input()
	a = x.split()
	for i in range(0, n):
		a[i] = int(a[i])
	if n == 1:
		s.append(a[0])
	else:
		j = 1
		while d != 0:
			if d >= j and a[j] != 0:
				d -= j
				a[j] -= 1
				a[0] += 1
			if d < j:
				break
			if a[j] == 0:
				j += 1
			if j == n:
				break
		s.append(a[0])
for i in s:
	print(i)


for _ in range(int(input())):
	(n, days) = list(map(int, input().split()))
	nums = list(map(int, input().split()))
	i = 1
	i = 1
	while i < n:
		if nums[i] * i > days:
			break
		days -= nums[i] * i
		nums[0] += nums[i]
		i += 1
	if days > 0 and i < n:
		k = days // i
		nums[0] += k
	print(nums[0])


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split(' '))
	l = [int(x) for x in input().split(' ')]
	for k in range(1, n):
		m = min(d, l[k] * k)
		l[0] += m // k
		d -= m
		k += 1
	print(l[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
	else:
		while d > 0:
			for i in range(1, n):
				if a[i] > 0:
					a[i - 1] += 1
					a[i] -= 1
					break
			d -= 1
		print(a[0])


q = int(input())
for w in range(q):
	(n, t) = map(int, input().split())
	a = input().split(' ')
	k = 0
	for i in range(t):
		for m in range(n - 1):
			if int(a[m + 1]) != 0:
				a[m] = int(a[m]) + 1
				a[m + 1] = int(a[m + 1]) - 1
				k += 1
			if k != 0:
				k = 0
				break
	print(a[0])


def solve(n, d, arr):
	i = 1
	while d > 0 and i < n:
		if arr[i] <= 0 or d < i:
			i += 1
		elif d >= i:
			d -= i
			arr[0] += 1
			arr[i] -= 1
	return arr[0]
t = int(input())
results = list()
for _ in range(0, t):
	(n, d) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	results.append(solve(n, d, arr))
for result in results:
	print(result)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	cnt1 = 0
	for i in range(1, a):
		cnt = 0
		if l[i] > 0:
			for j in range(1, l[i] + 1):
				if j < int(b / i):
					cnt += 1
				elif j == int(b / i):
					cnt += 1
					break
				else:
					break
			cnt1 += cnt
			b = b - cnt * i
		if b == 0 or i > b:
			break
	print(l[0] + cnt1)


import sys, math

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

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

def lmii():
	return list(mii())

def main():
	for _ in range(ii()):
		(n, d) = mii()
		x = lmii()
		ans = x[0]
		p = 1
		for i in range(1, n):
			r = d // p
			ans += min(r, x[i])
			d -= p * min(r, x[i])
			if r == 0:
				d = 0
			p += 1
		print(ans)
main()


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 1
	while d > 0 and i < n:
		move = min(a[i] * i, d)
		a[0] += move // i
		d -= move
		i += 1
	print(a[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	ar = list(map(int, input().split()))
	ans = 0
	idx = 1
	while n > 1 and idx < n and (d > 0):
		if ar[idx] == 0:
			idx += 1
			continue
		div = int(d / idx)
		if div == 0:
			break
		if ar[idx] >= div:
			ans += div
			break
		else:
			ans += ar[idx]
			d -= ar[idx] * idx
			idx += 1
	print(ans + ar[0])


T = input()
D = []
V = []
for t in range(int(T)):
	SD = list(input().split())
	s = int(SD[0])
	d = int(SD[1])
	v = [int(item) for item in input().split()]
	D.append(d)
	V.append(v)
for t in range(int(T)):
	d = D[t]
	v = V[t]
	cost = 0
	add = v[0]
	for i in range(d):
		cost = 0
		for vv in range(1, len(v)):
			if v[vv] > 0:
				cost = vv
				break
		if d >= cost and cost != 0:
			d = d - cost
			add = add + 1
			v[cost] = v[cost] - 1
	print(add)


def work(lst, idx):
	lst[idx - 1] += 1
	lst[idx] -= 1
	return
T = int(input())
for test in range(T):
	count = 0
	(n, d) = map(int, input().split())
	lst = list(map(int, input().split()))
	for i in range(1, n):
		if count >= d:
			break
		if i == 1:
			while lst[i] > 0:
				if count >= d:
					break
				work(lst, i)
				count += 1
				if count >= d:
					break
		else:
			while lst[i] > 0:
				if count >= d:
					break
				for j in range(i, 0, -1):
					work(lst, j)
					count += 1
					if count >= d:
						break
	print(lst[0])


q = int(input())
for p in range(q):
	(n, d) = map(int, input().split())
	hay = [int(x) for x in input().split()]
	i = 1
	first = hay[0]
	for each in hay[1:]:
		if d >= each * i:
			first += each
			d -= each * i
		else:
			first += d // i
			break
		i += 1
	print(first)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	xs = list(map(int, input().split()))
	ans = xs[0]
	for (i, x) in enumerate(xs[1:], 1):
		r = min(d // i, x)
		ans += r
		d -= r * i
	print(ans)


def haybales(piles):
	n = piles[0]
	d = piles[1]
	a = piles[2]
	pile = a[0]
	if n == 1:
		return pile
	i = 1
	while True:
		if d < 0:
			return pile - 1
		if d == 0 or i == n:
			return pile
		if a[i] > 0:
			d -= i
			pile += 1
			a[i] -= 1
		else:
			i += 1
t = int(input().rstrip())
result = list()
for i in range(t):
	temp = list(map(int, input().rstrip().split()))
	n = temp[0]
	d = temp[1]
	a = list(map(int, input().rstrip().split()))
	result.append((n, d, a))
for i in result:
	print(haybales(i))


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = a[0]
	c = 1
	for i in range(1, n):
		while d >= c and a[i] > 0:
			ans += 1
			d -= c
			a[i] -= 1
		if d < c:
			break
		c += 1
	print(ans)


t = int(input())
while t:
	t += -1
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = l[0]
	for i in range(1, n):
		temp = i * l[i]
		if temp <= d:
			ans += l[i]
			d -= temp
		else:
			te = d // i
			ans += te
			break
	print(ans)


from pprint import pprint
import sys
input = sys.stdin.readline
q = int(input())
for _ in range(q):
	(n, d) = map(int, input().split())
	dat = list(map(int, input().split()))
	for _ in range(d):
		for i in range(1, n):
			if dat[i] > 0:
				dat[i] -= 1
				dat[i - 1] += 1
				break
	print(dat[0])


def sol(arr, n, d):
	if n == 1:
		print(arr[0])
		return
	i = 1
	while i <= d and i < n:
		if arr[i] == 0:
			i += 1
		else:
			arr[0] += 1
			arr[i] -= 1
			d = d - i
	if d < 0:
		arr[0] -= 1
		arr[i] += 1
	print(arr[0])
k = int(input())
for i in range(k):
	(n, d) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	sol(arr, n, d)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	i = 1
	while d > 0 and i < n:
		x = min(a[i], d // i)
		ans += x
		d -= x * i
		i += 1
	print(ans + a[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 1
	ans = a[0]
	while d and i < n:
		y = i * a[i]
		if d >= y:
			ans += a[i]
			d -= y
		else:
			x = d // i
			ans += x
			break
		i += 1
	print(ans)


q = int(input())
for i in range(q):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		for j in range(a[i]):
			if d >= i:
				d -= i
				ans += 1
	print(ans)


for _ in range(int(input())):
	(nb_piles, days) = [int(x) for x in input().split()]
	piles = [int(x) for x in input().split()]
	for i in range(1, nb_piles):
		can_move = min(days, piles[i] * i)
		can_move -= can_move % i
		move = can_move // i
		piles[0] += move
		days -= can_move
	print(piles[0])


import os
from io import BytesIO, IOBase
import sys

def main():
	for t in range(int(input())):
		(n, d) = map(int, input().split())
		a = list(map(int, input().split()))
		val = a[0]
		f = 1
		cd = 0
		j = 1
		k = 0
		i = 0
		while cd < d:
			(f1, f2) = (0, 0)
			if k % 2 == 0:
				if i + j < n:
					val += min(a[i + j], (d - cd) // f)
					cd += min(a[i + j] * f, (d - cd) // f * f)
				else:
					f1 = 1
			elif i - j > 0:
				val += a[i - j] // ((d - cd) // f)
				cd += min(a[i - j] * f, (d - cd) // f * f)
			else:
				f2 = 1
			if k % 2 == 1:
				f += 1
				j += 1
			if f1 and f2 or d - cd < f:
				break
			k += 1
		print(val)
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 math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, d) = LI()
		a = LI()
		for i in range(1, n):
			t = min(d // i, a[i])
			a[0] += t
			d -= i * t
		rr.append(a[0])
	return JA(rr, '\n')
print(main())


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	A = list(map(int, input().split()))
	ans = A[0]
	for i in range(1, n):
		while d >= i and A[i] >= 1:
			ans += 1
			d -= i
			A[i] -= 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, d) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	i = 1
	current = d
	result = 0
	while i < n and current > 0:
		if a[i] * i <= current:
			result = a[i] + result
			current = current - a[i] * i
		else:
			if current // i == 0:
				break
			result = current // i + result
			current = current - current // i * i
		i = i + 1
	print(result + a[0])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	piles = list(map(int, input().split()))
	res = piles[0]
	for i in range(1, len(piles)):
		while piles[i] > 0 and i <= m:
			res += 1
			m -= i
			piles[i] -= 1
	print(res)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil, pi, sin, cos, acos, atan
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(n, d) = inp()
	arr = list(inp())
	if n == 1:
		ans = arr[0]
	else:
		pt = 1
		ans = 0
		while True:
			if pt == n:
				break
			elif arr[pt] > 0:
				d -= pt
				arr[pt] -= 1
				if d >= 0:
					arr[0] += 1
				else:
					break
			else:
				pt += 1
	ans = arr[0]
	out(ans)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	m = l[0]
	for i in range(1, a):
		for j in range(l[i]):
			if b >= i and l[i] > 0:
				b -= i
				l[i] -= 1
				m += 1
			else:
				break
	print(m)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	cost = a[0]
	for j in range(1, n):
		if d >= a[j] * j:
			cost = cost + a[j]
			d = d - a[j] * j
		else:
			cost = cost + d // j
			break
	print(cost)


from sys import stdin, stdout
rl = lambda : stdin.readline()
rll = lambda : stdin.readline().split()

def main():
	T = int(rl())
	for _ in range(T):
		(n, d) = (int(x) for x in rll())
		A = [int(x) for x in rll()]
		(ans, curr_day) = (A[0], 1)
		for pile in range(1, len(A)):
			while curr_day <= d and A[pile] > 0:
				if d - pile < 0:
					break
				A[pile] -= 1
				d -= pile
				ans += 1
		stdout.write(str(ans))
		stdout.write('\n')
	stdout.close()
main()


def f():
	t = int(input())
	for _ in range(t):
		_input = input()
		n = int(_input.split(' ')[0])
		d = int(_input.split(' ')[1])
		a = list(map(int, input().split(' ')))
		cost = 1
		ret = a[0]
		for x in a[1:]:
			tmp = min(d // cost, x)
			ret += tmp
			d -= tmp * cost
			cost += 1
		print(ret)
f()


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

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

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

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, k) = In()
		l = list(In())
		for x in range(1, n):
			t = k // x
			l[0] += min(t, l[x])
			k -= min(t, l[x]) * x
			if k <= 0:
				break
		print(l[0])
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	a = [int(i) for i in input().split()]
	if n == 1:
		print(a[0])
	elif a[1] > d:
		print(a[0] + d)
	else:
		is_printed = False
		while d >= 1:
			is_all = True
			for j in range(1, n):
				if a[j] != 0:
					is_all = False
					a[j - 1] += 1
					a[j] -= 1
					d -= 1
					break
			if is_all:
				is_printed = True
				print(a[0])
				break
		if not is_printed:
			print(a[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(1, n):
		tem = min(a[i], d // i)
		d -= tem * i
		a[0] += tem
	print(a[0])


for i in ' ' * int(input()):
	(n, d) = map(int, input().split())
	a = [int(i) for i in input().split()]
	lvl = 0
	for j in range(1, len(a)):
		while a[j] > 0 and d - 1 - lvl >= 0:
			a[0] += 1
			a[j] -= 1
			d -= 1 + lvl
		lvl += 1
	print(a[0])


t = int(input())
while t > 0:
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(1, n):
		if d <= 0:
			break
		if arr[i] == 0:
			continue
		if arr[i] * i > d:
			arr[0] += d // i
			break
		else:
			d -= i * arr[i]
			arr[0] += arr[i]
	print(arr[0])
	t -= 1


t = int(input())
for _ in range(t):
	(n, d) = (int(i) for i in input().split())
	a = (int(i) for i in input().split())
	res = next(a)
	for (i, e) in enumerate(a):
		res += min(d, (i + 1) * e) // (i + 1)
		d -= (i + 1) * e
		if d <= 0:
			break
	print(res)


def main_function():
	output_list = []
	t = int(input())
	for i in range(t):
		(n, d) = [int(i) for i in input().split(' ')]
		if n == 1:
			a = [int(i) for i in input().split(' ')]
			output_list.append(str(a[0]))
			continue
		a = [int(i) for i in input().split(' ')]
		b = [a[i] * i for i in range(1, len(a))]
		count = a[0]
		for i in range(len(b)):
			if d >= b[i]:
				count += b[i] // (i + 1)
				d -= b[i]
			elif d < i + 1:
				break
			elif d < b[i]:
				count += d // (i + 1)
				break
		output_list.append(str(count))
	return '\n'.join(output_list)
print(main_function())


def main():
	t = int(input())
	while t:
		t -= 1
		(n, d) = map(int, input().split())
		a = list(map(int, input().split()))
		for i in range(1, len(a)):
			if i * a[i] <= d:
				d -= i * a[i]
				a[0] += a[i]
			else:
				a[0] += d // i
				break
		print(a[0])
main()


for x in range(int(input())):
	(l, r) = map(int, input().strip().split()[:2])
	p = list(map(int, input().strip().split()[:l]))
	z = [p[0]]
	for y in range(1, l):
		s = 0
		if p[y] != 0:
			k = y
			s = min(p[y], r // y)
			z.append(s)
			r -= k * s
	print(sum(z))


t = int(input())
for case in range(t):
	(n, d) = [int(s) for s in input().split(' ')]
	a = [int(s) for s in input().split(' ')]
	i = 1
	while d > 0 and i < n:
		e = min(a[i] * i, d)
		a[0] += e // i
		a[i] -= e // i
		d -= e
		i += 1
	print(a[0])


def solve(n, d, a):
	result = a[0]
	idx = 1
	multiplier = 1
	while idx < n and d >= multiplier:
		current_stock = a[idx]
		while current_stock > 0 and d >= multiplier:
			result += 1
			current_stock -= 1
			d -= multiplier * 1
		idx += 1
		multiplier += 1
	return result
t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	result = solve(n, d, a)
	print(result)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	s = 0
	for j in range(1, n):
		d1 = d // j
		if a[j] >= d1:
			s += d1
			break
		else:
			s += a[j]
			d -= j * a[j]
	print(a[0] + s)


t = int(input())
for i in range(t):
	r = [int(x) for x in input().split()]
	s = [int(x) for x in input().split()]
	t = 1
	while r[1] >= t and t < r[0]:
		if s[t] == 0:
			t += 1
		else:
			s[t] -= 1
			r[1] -= t
			s[0] += 1
	print(s[0])


a = int(input())
for i in range(a):
	(n, d) = map(int, input().split())
	k = list(map(int, input().split()))
	ans = k[0]
	for j in range(1, n):
		co = min(k[j], d // j)
		d -= co * j
		ans += co
	print(ans)


for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	s = [int(x) for x in input().split()]
	ans = s[0]
	for i in range(1, a):
		if b >= i:
			k = min(b // i, s[i])
			b -= k * i
			ans += k
	print(ans)


for _ in range(int(input())):
	(n, d) = list(map(int, input().split()))
	r = i = 0
	for x in list(map(int, input().split())):
		if i * x > d:
			r += d // i
			break
		d -= i * x
		r += x
		i += 1
	print(r)


t = int(input())
while t:
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	count = a[0]
	for i in range(1, len(a)):
		k = a[i]
		while k != 0:
			if d < i:
				break
			count += 1
			d -= i
			k -= 1
		if d == 0:
			break
	print(count)
	t -= 1


T = int(input())
for i in range(T):
	line = input().split(' ')
	N = int(line[0])
	days = int(line[1])
	hayballs = list(map(lambda x: int(x), input().split(' ')))
	numof_hayballs = hayballs[0]
	for h in range(1, N):
		if days <= 0:
			break
		days_per_one_hayball = h
		if days // days_per_one_hayball >= hayballs[h]:
			added_hayballs = hayballs[h]
		else:
			added_hayballs = days // days_per_one_hayball
		days -= added_hayballs * days_per_one_hayball
		numof_hayballs += added_hayballs
	print(numof_hayballs)


def main():
	t = int(input())
	for _ in range(t):
		(n, d) = map(int, input().split())
		piles = list(map(int, input().split()))
		res = piles[0]
		for i in range(1, n):
			while d >= i and piles[i] > 0:
				d -= i
				piles[i] -= 1
				res += 1
		print(res)
main()


for i in range(int(input())):
	(n, d) = map(int, input().split())
	a = tuple(map(int, input().split()))
	cnt = a[0]
	for i in range(1, n):
		if a[i] * i < d:
			cnt += a[i]
			d -= a[i] * i
		else:
			cnt += d // i
			break
	print(cnt)


for u in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	i = 1
	c = 0
	while i < n and c <= k:
		if l[i] == 0:
			i = i + 1
		elif k - c >= i:
			c = c + i
			l[0] = l[0] + 1
			l[i] = l[i] - 1
		else:
			break
	print(l[0])


tc = int(input())
for T in range(tc):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	(res, day) = (arr[0], 0)
	for i in range(1, n):
		if arr[i] != 0:
			aa = min(arr[i], d // i)
			res += aa
			d -= aa * i
		if i > d:
			break
	print(res)


n = int(input())
for _ in range(n):
	(dlina, d) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	for i in range(1, dlina):
		pr = arr[i] * i
		if pr <= d:
			arr[0] += arr[i]
			d -= pr
		else:
			arr[0] += d // i
			break
	print(arr[0])


for i in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	j = 1
	ans = 0
	while d > 0 and j < n:
		if d > a[j] * j:
			ans += a[j]
			d -= a[j] * j
		else:
			ans += d // j
			break
		j += 1
	print(ans + a[0])


for _ in [0] * int(input()):
	(_, b) = [int(h) for h in input().strip().split(' ')]
	n = [int(h) for h in input().strip().split(' ')]
	for i in range(len(n)):
		if n[i] != 0 and i != 0:
			if n[i] * i <= b:
				n[0] = n[0] + n[i]
				b = b - n[i] * i
			else:
				n[0] = n[0] + b // i
				b = 0
		if b <= 0 or i == len(n) - 1:
			print(n[0])
			break


def calc(d, a):
	if len(a) == 1:
		return a[0]
	res = a[0]
	for i in range(1, len(a)):
		if d < i:
			break
		c = min(a[i], d // i)
		res += c
		d -= c * i
	return res
N = int(input())
cases = []
for _ in range(N):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	cases.append((d, a))
for (d, a) in cases:
	print(calc(d, a))


n = int(input())
for i in range(n):
	l1 = [int(i) for i in input().split()]
	l2 = [int(i) for i in input().split()]
	for i in range(l1[1]):
		for j in range(1, l1[0]):
			if l2[j] == 0:
				continue
			else:
				l2[j] -= 1
				l2[j - 1] += 1
				break
	print(l2[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	c = 0
	c1 = 0
	for i in range(1, n):
		w = i * a[i]
		if c < d:
			p = d - c
			p1 = p // i
			c += min(p1, a[i]) * i
			c1 += min(p1, a[i])
		else:
			break
	print(c1 + a[0])


for t in range(int(input())):
	(n, d) = [int(i) for i in input().split()]
	l = [int(i) for i in input().split()]
	i = 1
	k = l[0]
	while d >= i and i < n:
		if l[i] > 0:
			l[i] -= 1
			k += 1
			d -= i
		else:
			i += 1
	print(k)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = arr[0]
	for i in range(1, n):
		if arr[i] * i <= d:
			ans += arr[i]
			d -= arr[i] * i
		else:
			ans += d // i
			break
	print(ans)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	ar = list(map(int, input().split()))
	count = ar[0]
	for i in range(1, n):
		if d >= ar[i] * i:
			d -= ar[i] * i
			count += ar[i]
		else:
			count += d // i
			d -= d // i * i
	print(count)


t = int(input())
for i in range(t):
	l1 = input()
	l2 = input()
	(n, d) = list(map(int, l1.split(' ')))
	a = list(map(int, l2.split(' ')))
	j = 1
	while d > 0 and j < n:
		temp = min(d // j, a[j])
		if temp * j <= d:
			a[0] += temp
			d -= temp * j
		else:
			d = 0
		j += 1
	print(a[0])


t = int(input())
while t:
	(n, d) = map(int, input().split())
	a = input().split()
	for i in range(n):
		a[i] = int(a[i])
	ans = a[0]
	for i in range(1, n):
		ans += min(d // i, a[i])
		d -= min(d // i, a[i]) * i
	print(ans)
	t -= 1


t = int(input())

def find(y, arr):
	days = y
	res = arr[0]
	for l in range(1, len(arr)):
		for k in range(0, arr[l]):
			if days < l:
				break
			res += 1
			days -= l
	print(res)
for i in range(t):
	(x, y) = map(int, input().split())
	arr = list(map(int, input().split()))
	find(y, arr)


n = int(input())
for i in range(n):
	r = input()
	arr1 = r.split()
	for i in range(2):
		arr1[i] = int(arr1[i])
	x = input()
	arr2 = x.split()
	for i in range(arr1[0]):
		arr2[i] = int(arr2[i])
	day = arr1[1]
	p = 1
	p = int(p)
	if arr1[0] == 1:
		print(arr2[0])
	else:
		while day >= p & p < arr1[0]:
			if arr2[p] != 0:
				arr2[0] += 1
				arr2[p] -= 1
				day -= p
			else:
				p += 1
		print(arr2[0])


def take(lst, y, j, fl):
	if j < len(lst):
		if y <= lst[j] * j:
			lst[0] += y // j
			lst[j] -= y // j
			y = y // j
			fl = False
		elif j <= y:
			y -= lst[j] * j
			lst[0] += lst[j]
			lst[j] = 0
		else:
			fl = False
	else:
		fl = False
	return (lst, y, fl)
t = int(input())
for k in range(t):
	flag = True
	(n, d) = map(int, input().split())
	aList = list(map(int, input().split()))
	for i in range(n):
		if flag:
			(aList, d, flag) = take(aList, d, i + 1, flag)
	print(aList[0])
	aList = []


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	d1 = d
	a = list(map(int, input().split()))
	(m, t, ind) = (a[0], 0, -1)
	for i in range(1, n):
		t += i * a[i]
		if t > d:
			ind = i
			break
		else:
			m += a[i]
			d1 -= i * a[i]
	if ind == -1:
		print(m)
	else:
		m += d1 // ind
		print(m)


test = int(input())
for t in range(test):
	nd = list(map(int, input().split()))
	(n, d) = (nd[0], nd[1])
	L = list(map(int, input().split()))
	for i in range(1, n):
		if L[i] == 0:
			continue
		else:
			maxmove = d // i
			if maxmove <= L[i]:
				L[0] += maxmove
				d = d - maxmove * i
			else:
				L[0] += L[i]
				d = d - L[i] * i
	print(L[0])


a = int(input())
for i in range(0, a):
	arr = list(map(int, input().split()))
	brr = list(map(int, input().split()))
	count = brr[0]
	for i in range(1, len(brr)):
		while arr[1] >= i and brr[i] > 0:
			count = count + 1
			brr[i] = brr[i] - 1
			arr[1] = arr[1] - i
	print(count)


t = int(input())
for it in range(t):
	(n, d) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	for i in range(d):
		for i in range(1, len(a)):
			if a[i] > 0:
				a[i] -= 1
				a[i - 1] += 1
				break
	print(a[0])


for tc in range(int(input())):
	(n, d) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	ans = a[0]
	for i in range(1, n):
		if d > i * a[i]:
			d -= i * a[i]
			ans += a[i]
		else:
			ans += d // i
			break
	print(ans)


import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))
go = lambda : 1 / 0

def write(*args, sep='\n'):
	for i in args:
		sys.stdout.write('{}{}'.format(i, sep))
INF = float('inf')
MOD = int(1000000000.0 + 7)
YES = 'YES'
NO = 'NO'
for _ in range(int(input())):
	try:
		(n, d) = read()
		arr = read()
		if n == 1:
			print(arr[0])
			go()
		for i in range(d):
			for j in range(1, n):
				if arr[j] > 0:
					arr[j - 1] += 1
					arr[j] -= 1
					break
		print(arr[0])
	except ZeroDivisionError:
		continue
	except Exception as e:
		print(e)
		continue


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(1, n):
		k = min(a[i], m // i)
		m -= k * i
		a[0] += k
	print(a[0])


def solve():
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(1, n):
		while arr[i] > 0:
			if d - i >= 0:
				d -= i
				arr[0] += 1
				arr[i] -= 1
			else:
				break
	print(arr[0])
for _ in range(int(input())):
	solve()


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, d) = R()
	a = (*R(),)
	r = i = 0
	while i < n and i * a[i] <= d:
		d -= i * a[i]
		r += a[i]
		i += 1
	if i < n:
		r += d // i
	print(r)


q = int(input())
for u in range(q):
	(n, d) = [int(i) for i in input().split()]
	s = [int(i) for i in input().split()]
	(su, i) = (0, 1)
	if n == 1:
		print(s[0])
	else:
		while i != n and su < d:
			if s[i] * i <= d - su:
				su += s[i] * i
				s[0] += s[i]
			else:
				s[0] += (d - su) // i
				su = d
			i += 1
		print(s[0])


from math import *
import sys, random

def nextInt():
	return int(input())

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

def nextInts():
	return list(map(int, nextStrs()))

def main():
	t = nextInt()
	while t > 0:
		(n, d) = nextInts()
		arr = nextInts()
		for i in range(1, n):
			arr[0] += min(arr[i], d // i)
			d -= min(arr[i], d // i) * i
		print(arr[0])
		t -= 1
exit(main())


def readLine():
	return list(map(int, input().split()))
t = int(input())
for _ in range(t):
	(n, d) = readLine()
	a = readLine()
	for i in range(1, n):
		if d <= 0:
			break
		dn = i * a[i]
		if d >= dn:
			a[0] += a[i]
			d -= dn
		else:
			dreq = d // i
			a[0] += dreq
			break
	print(a[0])


import math, collections, sys
input = sys.stdin.readline

def case():
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(1, n):
		while a[i]:
			if d >= i:
				a[i] -= 1
				a[0] += 1
				d -= i
			else:
				break
	print(a[0])
for _ in range(int(input())):
	case()


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

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

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

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, d) = inputnums()
	a = inputlist()
	ans = a[0]
	for i in range(1, n):
		while d >= i and a[i] > 0:
			a[i] -= 1
			ans += 1
			d -= i
	print(ans)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(1, n):
		k = min(a[i] * i, d) // i
		a[0] += k
		d -= k * i
	print(a[0])


t = int(input())
for _ in range(t):
	[n, d] = [int(x) for x in input().split(' ')]
	piles = [int(x) for x in input().split(' ')]
	for _ in range(d):
		first_idx = None
		for i in range(1, len(piles)):
			if piles[i] > 0:
				first_idx = i
				break
		if first_idx == None:
			break
		piles[first_idx] -= 1
		piles[first_idx - 1] += 1
	print(piles[0])


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(1, n):
		x = d // i
		x = min(x, a[i])
		a[0] += x
		d -= x * i
	print(a[0])


t = int(input())
while t > 0:
	inp = input().split(' ')
	n = int(inp[0])
	d = int(inp[1])
	pile = input().split(' ')
	pile = list(map(int, pile))
	pile1 = pile[0]
	pile.remove(pile1)
	for i in range(n - 1):
		while d >= i + 1 and pile[i] > 0:
			pile1 += 1
			pile[i] -= 1
			d -= i + 1
	print(pile1)
	t -= 1


T_ON = 1
DEBUG_ON = 0
MOD = 998244353

def solve():
	(n, d) = read_ints()
	A = read_ints()
	for i in range(1, n):
		x = min(d // i, A[i])
		A[0] += x
		d -= x * i
	print(A[0])

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
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 read_int():
	return int(input())

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

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

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

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

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

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


def count_max_haybales_on_first_pile(n, d, piles):
	points = piles[0]
	for (i, pile) in enumerate(piles[1:]):
		i = i + 1
		max_to_move = int(d / i)
		if max_to_move == 0:
			return points
		f = min(max_to_move, pile)
		points += f
		d -= f * i
	return points
t = int(input())
for i in range(t):
	d_n = list(map(lambda x: int(x), input().split()))
	n = d_n[0]
	d = d_n[1]
	piles = list(map(lambda x: int(x), input().split()))
	print(count_max_haybales_on_first_pile(n, d, piles))


t = int(input())
for i in range(t):
	(n, d) = [int(i) for i in input().split()]
	haybales = [int(i) for i in input().split()]
	res = haybales[0]
	for i in range(1, n):
		while d >= i and haybales[i] > 0:
			d -= i
			haybales[i] -= 1
			res += 1
	print(res)


def I():
	return map(int, input().split())
for _ in range(int(input())):
	(n, d) = I()
	a = list(I())
	i = 1
	while d and i < len(a):
		if d < i:
			break
		elif a[i]:
			a[0] += 1
			d -= i
			a[i] -= 1
		else:
			i += 1
	print(a[0])


from math import ceil
for _ in range(int(input())):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	x = l[0]
	for i in range(1, n):
		d -= i * l[i]
		x += l[i]
		if d == 0:
			break
		elif d < 0:
			x -= ceil(-d / i)
			break
	print(x)


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

def si():
	return input()

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

def li():
	return list(mi())
import math
for i in range(ii()):
	(n, d) = mi()
	a = li()
	c = 0
	for i in range(1, n):
		while a[i] > 0:
			a[i] -= 1
			c += i
			if c <= d:
				a[0] += 1
			else:
				break
		if c > d:
			break
	print(a[0])


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
for _ in range(get_int()):
	(n, d) = get_int_list()
	piles = get_int_list()
	count = piles[0]
	for i in range(1, n):
		if d > 0:
			if i * piles[i] <= d:
				count += piles[i]
				d -= i * piles[i]
			else:
				count += d // i
				d = 0
		else:
			break
	print(count)


t = int(input())
for i in range(t):
	b = 1
	c = input().split()
	n = int(c[0])
	d = int(c[1])
	while True:
		a = input().split()
		e = int(a[0])
		if len(a) == n:
			break
	for j in a[1:]:
		g = d // b
		f = min(int(j), g)
		e = e + f
		d = d - f * b
		b = b + 1
		if d < b:
			break
	print(e)


t = int(input())
res = []
for i in range(t):
	params = list(map(int, input().split()))
	n = params[0]
	d = params[1]
	piles = input()
	piles = list(map(int, piles.split()))
	sum = 0
	score = 1
	for i in range(1, len(piles)):
		pile = piles[i]
		max = pile * score
		if max >= d:
			piles[0] += d // score
			break
		else:
			piles[0] += pile
			d -= max
		score += 1
	res.append(piles[0])
print(*res, sep='\n')


for _ in range(int(input())):
	(n, d) = [int(x) for x in input().split()]
	p = [int(x) for x in input().split()]
	np = p[0]
	for i in range(1, n):
		if i * p[i] > d:
			np += d // i
			break
		np += p[i]
		d -= i * p[i]
	print(np)


l = int(input())
i = 0
for _ in range(l):
	i += 1
	(n, d) = map(int, input().split())
	if n == 0:
		print(0)
	else:
		i += 1
		p = list(map(int, input().split()))
		res = p[0]
		used = 0
		j = 1
		while True:
			if j >= len(p):
				break
			elif p[j] == 0:
				j += 1
			elif used + j > d:
				break
			else:
				used += j
				res += 1
				p[j] -= 1
		print(res)


def solve():
	(n, d) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	add = 0
	for i in range(1, n):
		if d >= i and a[i] > 0:
			x = min(a[i], d // i)
			add += x
			d = d - x * i
	print(a[0] + add)
t = int(input())
while t > 0:
	solve()
	t -= 1


for _ in range(int(input())):
	(n, d) = [int(__) for __ in input().split()]
	a = [int(___) for ___ in input().split()]
	if n == 1:
		print(a[0])
		continue
	i = 1
	while d > 0:
		if a[i] != 0:
			a[i] -= 1
			d -= i
			a[0] += 1
		elif i < n - 1:
			i += 1
		else:
			break
	if d < 0:
		print(a[0] - 1)
	else:
		print(a[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	lis = list(map(int, input().split()))
	s = sum(lis)
	t = 0
	while t < d and lis[0] < s:
		k = 1
		while lis[k] == 0 and k < len(lis):
			k += 1
		lis[k - 1] += 1
		lis[k] -= 1
		t += 1
	print(lis[0])


sets = int(input())
for i in range(sets):
	(stacks, days) = [int(i) for i in input().split()]
	bales = [int(i) for i in input().split()]
	counter = 0
	while days != 0 and counter != stacks - 1:
		counter += 1
		if bales[counter] * counter <= days:
			bales[0] += bales[counter]
			days -= bales[counter] * counter
		else:
			while bales[counter] * counter > days:
				bales[counter] -= 1
			bales[0] += bales[counter]
			break
	print(bales[0])


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

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

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

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

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

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

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

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
for _ in range(inn()):
	(n, d) = value()
	a = arr()
	for i in range(1, n):
		mn = min(d, a[i] * i)
		d -= mn
		a[0] += mn // i
	print(a[0])


n = int(input())
for i in range(n):
	(a, d) = map(int, input().split())
	s = list(map(int, input().split()))
	c = 1
	t = 0
	if a == 1:
		print(s[0])
	else:
		while d > 0:
			t = d // c
			if t >= s[c]:
				d -= s[c] * c
			else:
				d -= c * t
			s[0] += min(t, s[c])
			c += 1
			if c == a:
				break
		print(s[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	x = a[0]
	time = d
	for i in range(1, n):
		days = min(a[i] * i, time)
		x += days // i
		time -= days
		if time <= 0:
			break
	print(x)


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		A = list(map(int, input().split()))
		ans = 0
		for i in range(1, n):
			while A[i] and i <= m:
				A[0] += 1
				A[i] -= 1
				m -= i
		print(A[0])
main()


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	cnt = 0
	spnd = 0
	for i in range(1, n):
		cnt += min((d - spnd) // i, a[i])
		spnd += i * min((d - spnd) // i, a[i])
	print(cnt + a[0])


t = int(input())
for g in range(t):
	(n, d) = map(int, input().split())
	s = [int(f) for f in input().split()]
	a = s[0]
	for i in range(1, n):
		while d >= i and s[i] > 0:
			a += 1
			s[i] -= 1
			d -= i
	print(a)


x = input()
for i in range(int(x)):
	des = input()
	val = input()
	n = int(des.split(' ')[0])
	d = int(des.split(' ')[1])
	counter = 1
	list = val.split(' ')
	lemon = int(list[0])
	for i in list[1:]:
		if int(i) * counter <= d:
			d = d - int(i) * counter
			lemon = lemon + int(i)
			counter = counter + 1
		else:
			lemon = lemon + int(d / counter)
			break
	print(lemon)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	l = [*map(int, input().split())]
	for i in range(1, n):
		if d == 0:
			break
		x = min(d // i, l[i])
		l[0] += x
		d -= x * i
	print(l[0])


from __future__ import division, print_function
from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
import math
import os
import sys

def binNumber(n, size=1):
	return bin(n)[2:].zfill(size)

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

def ini():
	return int(input())

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

def instr():
	return str(input())

def main():
	(n, d) = insp()
	a = inar()
	ans = 0
	for i in range(1, n):
		x = min(a[i], d // i)
		ans += x
		d -= x * i
	print(ans + a[0])
t = ini()
while t > 0:
	t -= 1
	main()


def answer():
	n = int(input())
	while n:
		a = [int(x) for x in input().split()]
		d = a[1]
		b = [int(x) for x in input().split()]
		i = 1
		time = 0
		ans = b[0]
		while i < len(b) and time <= d:
			while b[i] > 0 and time + i <= d:
				b[i] -= 1
				time += i
				ans += 1
			i += 1
		print(ans)
		n -= 1
answer()


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = l[0]
	c = 1
	while d >= 0 and c < n:
		if l[c] == 0:
			c += 1
		else:
			d -= c
			if d < 0:
				break
			ans += 1
			l[c] -= 1
	print(ans)


def solve(n, d, arr):
	cnt = 0
	for j in range(1, n):
		if d < j:
			break
		if arr[j] == 0:
			continue
		allow = min(arr[j], d // j)
		d -= allow * j
		cnt += allow
	return arr[0] + cnt
	pass
t = int(input())
ans = []
for i in range(t):
	s = [int(x) for x in input().split()]
	n = s[0]
	d = s[1]
	arr = [int(x) for x in input().split()]
	ans.append(solve(n, d, arr))
for test in ans:
	print(test)


t = int(input())
while t > 0:
	(n, d) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	for i in range(d):
		for (index, j) in enumerate(arr):
			if index == 0 or j == 0:
				continue
			if j != 0:
				arr[index] -= 1
				arr[index - 1] += 1
				break
	print(arr[0])
	t -= 1


t = int(input())
for i in range(t):
	entrada = list(map(int, input().split()))
	n = entrada[0]
	d = entrada[1]
	ni = list(map(int, input().split()))
	out = ni[0]
	for i in range(1, len(ni)):
		if d > 0:
			cost = ni[i] * i
			if cost > d:
				out += int(d / i)
				d -= int(d / i) * i
			else:
				out += ni[i]
				d -= cost
		else:
			break
	print(out)


count_test = int(input())
arrs = []
res = []

def calc(count_day, count_in_one):
	res_c = count_in_one[0]
	count_in_one = count_in_one[1:]
	steps_lost = count_day
	for (current_pos, num_stocks) in enumerate(count_in_one):
		if num_stocks == 0:
			continue
		if steps_lost < 0:
			return res_c
		for _ in range(num_stocks):
			steps_lost -= current_pos + 1
			if steps_lost < 0:
				return res_c
			res_c += 1
	return res_c
for _ in range(count_test):
	n1 = input()
	n2 = input()
	arr1 = [int(i) for i in n1.split(' ')]
	arr2 = [int(i) for i in n2.split(' ')]
	count_haystacks = arr1[0]
	count_day = arr1[1]
	count_in_one = [int(i) for i in arr2]
	c = calc(count_day, count_in_one)
	res.append(c)
for i in res:
	print(i)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	for x in range(m):
		for y in range(1, n):
			if a[y] > 0:
				a[y - 1] += 1
				a[y] -= 1
				break
	print(a[0])


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	for j in range(1, n):
		while l[j] > 0 and j <= d:
			l[0] += 1
			l[j] -= 1
			d -= j
	print(l[0])


sp = lambda : list(map(int, input().split()))
si = lambda : int(input())
TESTCASES = int(input())
out = []
for tc in range(TESTCASES):
	(n, d) = sp()
	haybales = sp()
	ans = haybales[0]
	for (i, h) in enumerate(haybales):
		if i == 0:
			continue
		if d >= i:
			minh = min(d // i, h)
			d -= i * minh
			ans += minh
		if d < i:
			break
	out.append(str(ans))
print('\n'.join(out))


def max_hay(d, a):
	count = a[0]
	for i in range(1, len(a)):
		h = min(a[i], d // i)
		count += h
		d -= h * i
		if d <= 0:
			break
	return count
num = int(input())
for _ in range(num):
	(n, d) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	print(max_hay(d, a))


t = int(input())
while t != 0:
	t -= 1
	(n, d) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	for i in range(1, len(a)):
		while a[i] != 0:
			if d - i < 0:
				break
			a[0] += 1
			a[i] -= 1
			d -= i
	print(a[0])


i = lambda : [*map(int, input().split())]
for _ in [0] * i()[0]:
	(n, d) = i()
	a = i()
	k = 1
	while k < n and d > 0:
		l = min(d // k, a[k])
		a[0] += l
		d -= a[k] * k
		k += 1
	print(a[0])


import sys
read = lambda : list(map(int, sys.stdin.readline().strip().split()))
for i in range(int(input())):
	(n, d) = read()
	a = read()
	count = a[0]
	for ind in range(1, n):
		temp = a[ind]
		(quo, rem) = divmod(d, ind)
		if quo == 0:
			break
		if quo >= temp:
			count += temp
			d -= temp * ind
		else:
			count += quo
			d = rem
	print(count)


from sys import stdin, stdout, setrecursionlimit
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	for i in range(1, n):
		while k - i >= 0 and a[i] > 0:
			a[0] += 1
			a[i] -= 1
			k -= i
	print(a[0])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = [] + list(map(int, input().split()))
	i = 1
	if len(s) != 1:
		while m // i != 0 and i <= n - 1:
			if s[i] != 0:
				if m > s[i] * i:
					s[0] += s[i]
					s[i] == 0
					m -= s[i] * i
				else:
					s[0] += m // i
					break
			i += 1
		print(s[0])
	else:
		print(s[0])


import math
x = int(input())
for a in range(x):
	y = str(input()).split(' ')
	z = str(input()).split(' ')
	dias = int(y[1])
	vetor = [int(z[b]) for b in range(len(z))]
	total = vetor[0]
	for b in range(1, len(z)):
		if dias > 0:
			custo = vetor[b] * b
			if custo <= dias:
				total += vetor[b]
				dias -= custo
			else:
				total += dias // b
				dias -= dias // b * b
		else:
			break
	print(total)


T = int(input())
for _ in range(T):
	(n, d) = map(int, input().split(' '))
	haybales = [int(i) for i in input().split(' ')]
	initial = haybales[0]
	days = 0
	for i in range(1, n):
		if haybales[i] * i >= d - days:
			initial += (d - days) // i
			break
		else:
			initial += haybales[i]
			days += haybales[i] * i
	print(initial)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	s = list(map(int, input().split()))
	for i in range(1, len(s)):
		if d >= i * s[i]:
			s[0] += s[i]
			d -= i * s[i]
		else:
			s[0] += d // i
			break
	print(s[0])


t = int(input())
for i in range(t):
	(num_piles, num_days) = [int(j) for j in input().split()]
	hay_list = [int(j) for j in input().split()]
	for index in range(1, len(hay_list)):
		if num_days == 0:
			break
		if hay_list[index] == 0:
			continue
		while num_days > 0 and hay_list[index] > 0:
			if num_days >= index:
				num_days -= index
				hay_list[index] -= 1
				hay_list[0] += 1
			else:
				break
	print(hay_list[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	al = list(map(int, input().split()))
	for i in range(d):
		for i in range(0, n - 1):
			if al[i + 1] != 0:
				al[i] += 1
				al[i + 1] -= 1
				break
			else:
				continue
	print(al[0])


for _ in range(int(input())):
	(n, d) = list(map(int, input().split()))
	li = list(map(int, input().split()))
	res = li[0]
	for i in range(1, n):
		x = min(li[i], d // i)
		res += x
		d -= x * i
	print(res)


t = int(input())
while t > 0:
	t -= 1
	(n, d) = [int(k) for k in input().split()]
	a = [int(k) for k in input().split()]
	answer = a[0]
	for (i, item) in enumerate(a[1:], 1):
		if d >= i:
			toMove = min(i * (d // i), item * i)
			answer += toMove / i
			d -= toMove
		else:
			break
	print(int(answer))


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	(n, d) = Read.list_int()
	a = Read.list_int()
	result = 0
	for i in range(n - 1):
		f = min(a[i + 1], math.floor(d / (i + 1)))
		d -= f * (i + 1)
		result += f
	print(result + a[0])
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


import math
T = int(input())
for i in range(T):
	(n, d) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	total = a[0]
	for j in range(1, n):
		suma = math.floor(d / j)
		ha = min(suma, a[j])
		total += ha
		d -= ha * j
	print(total)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	ai = list(map(int, input().split()))
	j = 1
	while d >= j and j < n:
		num = min(ai[j], d // j)
		ai[0] += num
		d -= num * j
		j += 1
	print(ai[0])


def sol(L, d):
	c = L[0]
	i = 1
	while i < len(L):
		if L[i] == 0:
			i += 1
			continue
		d -= i
		L[i] -= 1
		c += 1
		if d < 0:
			c -= 1
			return c
	return c
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	X = input().split()
	assert len(X) == a
	for j in range(a):
		X[j] = int(X[j])
	print(sol(X, b))


haypiles = []
days = []
a = []
testNum = int(input())
for i in range(testNum):
	line2 = input().split()
	haypiles.append(int(line2[0]))
	days.append(int(line2[1]))
	line3 = input().split()
	for j in range(haypiles[i]):
		line3[j] = int(line3[j])
	a.append(line3)
for t in range(testNum):
	if haypiles[t] == 1:
		print(a[t][0])
		continue
	while days[t] > 0:
		breakDone = False
		i = 0
		while True:
			if a[t][i + 1] > 0:
				a[t][i + 1] -= 1
				a[t][i] += 1
				i = 0
				days[t] -= 1
				breakDone = True
				break
			i += 1
			if i >= haypiles[t] - 1:
				break
		if not breakDone:
			days[t] = 0
	print(a[t][0])


t = int(input())
for _ in range(0, t):
	(n, d) = map(int, input().split())
	ans = 0
	a = list(map(int, input().split()))
	for i in range(0, n):
		if i * a[i] <= d:
			ans += a[i]
			d -= i * a[i]
		else:
			ans += d // i
			d = 0
	print(ans)


from copy import copy
from math import *

def arr_float_inp():
	return [float(s) for s in input().split()]

def arr_int_inp():
	return [int(s) for s in input().split()]

def int_inp():
	return int(input())

def float_inp():
	return float(input())

def comp(a):
	return a[0]

def gcd(a, b):
	if b != 0:
		return gcd(b, a % b)
	else:
		return a
for _ in range(int_inp()):
	(n, d) = arr_int_inp()
	a = arr_int_inp()
	i = 1
	ans = a[0]
	while d > 0 and i < n:
		while a[i] > 0:
			d -= i
			if d >= 0:
				ans += 1
				a[i] -= 1
			else:
				d += i
				break
		i += 1
	print(ans)


t = int(input())
for w in range(t):
	(n, d) = (int(i) for i in input().split())
	l = [int(i) for i in input().split()]
	for i in range(1, n):
		if d > 0:
			k = min(d // i, l[i])
			l[0] += k
			d -= i * k
		else:
			break
	print(l[0])


for i in range(int(input())):
	(l, days) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(days):
		for i in range(1, l):
			if a[i] > 0:
				a[i - 1] += 1
				a[i] -= 1
				break
	print(a[0])


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = [int(x) for x in input().split()]
	ans = a[0]
	c = 0
	days = 0
	for i in a[1:]:
		c += 1
		if days + c * i <= d:
			days += c * i
			ans += i
		else:
			ans += (d - days) // c
			break
	print(ans)


case = int(input())
for i in range(case):
	(n, d) = map(int, input().split())
	v = [int(i) for i in input().split()]
	du = d
	j = 1
	ans = v[0]
	while d > 0 and j < n:
		if v[j] != 0:
			if j > d:
				d = 0
				break
			else:
				ans += 1
				d -= j
				v[j] -= 1
		else:
			j += 1
	print(ans)


n = int(input())
for test in range(n):
	a = list(map(int, input().split()))
	day = a[1]
	nums = list(map(int, input().split()))
	res = nums[0]
	index = 1
	while index <= len(nums) - 1:
		move = min(nums[index], day // index)
		res += move
		day -= move * index
		index += 1
	print(res)


t = int(input())
for i in range(t):
	(n, d) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	res = 0
	for k in range(1, len(a)):
		if d >= k * a[k]:
			d -= k * a[k]
			res += a[k]
		elif d < k or a[k] == 0:
			break
		else:
			res += d // k
			d -= d // k * k
	print(res + a[0])


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
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').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	tot = 0
	(n, d) = li()
	l = li()
	tot = l[0]
	for i in range(1, n):
		while d >= i and l[i]:
			l[i] -= 1
			tot += 1
			d -= i
	print(tot)


q = int(input())
for _ in range(q):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	i = 1
	c = l[0]
	while i < n and d > 0:
		if l[i] * i <= d:
			c += l[i]
			d -= l[i] * i
		else:
			f = d // i
			c += f
			break
		i += 1
	print(c)


import math
n = int(input())
Result = []
for i in range(0, n):
	Sum = []
	var = False
	DaysElements = list(map(int, input().strip().split()))[:2]
	current_days = DaysElements[1]
	len_ = DaysElements[0]
	Elements = list(map(int, input().strip().split()))[:len_]
	if len_ <= 1:
		Result.append(Elements[0])
		continue
	current_index_pointer = 1
	for j in range(1, len_):
		current_high = math.floor(current_days / current_index_pointer)
		if Elements[j] <= current_high:
			current_days = current_days - Elements[j] * current_index_pointer
			Sum.append(Elements[j])
		else:
			current_days = current_days - current_high * current_index_pointer
			Sum.append(current_high)
		current_index_pointer += 1
		if current_days < current_index_pointer:
			var = True
			Result.append(sum(Sum) + Elements[0])
			break
	if var is not True:
		Result.append(sum(Sum) + Elements[0])
for i in Result:
	print(i)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	ans = 0
	for (i, ai) in enumerate(map(int, input().split())):
		if i * ai >= d:
			ans += d // i
			break
		d -= i * ai
		ans += ai
	print(ans)


for i in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = a[0]
	e = 0
	for j in range(1, n):
		if a[j] != 0:
			b = d / a[j]
			if b <= j:
				e = e + 1
				if b == int(b):
					print(ans + int(d / j))
					break
				else:
					print(ans + int(d / j))
					break
				break
			else:
				d = d - a[j] * j
				ans = ans + a[j]
	if e == 0:
		print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, d) = map(int, input().split())
	lst = list(map(int, input().split()))
	cnt = 0
	for i in range(len(lst)):
		if lst[i] * i > d:
			cnt += d // i
			break
		cnt += lst[i]
		d -= lst[i] * i
	print(cnt)


try:
	input = raw_input
except NameError:
	pass
import math
from sys import stdin

def line():
	return stdin.readline().strip()
tc = int(line())
for _ in range(tc):
	(n, d) = map(int, line().split(' '))
	ar = line().split(' ')
	ar = [int(x) for x in ar]
	i = 1
	while d >= i and i < n:
		if ar[i]:
			ar[i] -= 1
			ar[0] += 1
			d -= i
		if not ar[i]:
			i += 1
	print(ar[0])


t = int(input())
while t:
	t -= 1
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = a[0]
	for i in range(1, n):
		div = d // i
		v = a[i]
		if div <= v:
			ans += div
			d -= div * i
		else:
			ans += v
			d -= v * i
	print(ans)


for _ in range(int(input())):
	(n, d) = list(map(int, input().strip().split()))
	array = list(map(int, input().strip().split()))
	ans = array[0]
	i = 1
	while d > 0 and i < n:
		if d - i >= 0 and array[i] > 0:
			ans += 1
			array[i] -= 1
			d -= i
		else:
			i += 1
	print(ans)


for saquif in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	rslt = a[0]
	for i in range(1, n):
		if d == 0:
			break
		if i * a[i] >= d:
			x = int(d / i)
			rslt += x
			d = 0
			break
		else:
			d -= i * a[i]
			rslt += a[i]
	print(rslt)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(v) for v in input().split()]
	for i in range(1, n):
		if a[i] and k > 0:
			while k > 0 and k >= i and (a[i] > 0):
				k = k - i
				a[0] += 1
				a[i] -= 1
	print(a[0])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	data = list(map(int, input().split()))
	for (index, value) in enumerate(data[1:]):
		index += 1
		potential = m // index
		if potential == 0:
			break
		incr = min(potential, value)
		data[0] += incr
		m = m - incr * index
	print(data[0])


class Solution:

	def solve(self, n, d, haybales):
		ans = haybales[0]
		for i in range(1, n):
			while haybales[i] > 0 and d >= i:
				ans += 1
				d -= i
				haybales[i] -= 1
		return ans
sol = Solution()
t = int(input().strip())
for i in range(t):
	[n, d] = list(map(int, input().strip().split()))
	haybales = list(map(int, input().strip().split()))
	print(sol.solve(n, d, haybales))


def main():
	t = int(input())
	for __ in range(t):
		(n, d) = map(int, input().split())
		a = list(map(int, input().split()))
		for i in range(1, n):
			if d >= 0 and a[i] >= 0:
				if a[i] > d // i:
					a[0] += d // i
					d = d % i
				else:
					a[0] += a[i]
					d -= i * a[i]
			if d == 0:
				break
		print(a[0])
main()


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	a = input().split()
	a = [int(i) for i in a]
	if n == 1:
		print(a[0])
		continue
	sum = a[0]
	i = 1
	while i <= d and i < n:
		if d > i * a[i]:
			sum = sum + a[i]
			d = d - i * a[i]
		else:
			k = d // i
			sum = sum + k
			d = 0
		i = i + 1
	print(sum)


import math
T = int(input())
for i in range(0, T):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()[:n]))
	if n == 1:
		print(arr[0])
		continue
	sum = 0
	for j in range(1, n):
		if k <= 0:
			break
		if arr[j] >= 1:
			if j * arr[j] <= k:
				sum += arr[j]
				k -= j * arr[j]
			else:
				sum += k // j
				break
	print(arr[0] + sum)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().strip().split())
	ls = list(map(int, input().strip().split()))
	ans = ls[0]
	for i in range(1, n):
		if ls[i] * i <= k:
			temp = ls[i]
			k -= temp * i
			ans += temp
		elif i <= k:
			temp = k // i
			k -= temp * i
			ans += temp
		else:
			break
		if k == 0:
			break
	print(ans)


t = int(input())
for i in range(t):
	l = input()
	l = l.split()
	n = int(l[0])
	d = int(l[1])
	l = input()
	l = l.split()
	ans = int(l[0])
	found = False
	for i in range(1, n):
		if int(l[i]) != 0 and d > 0:
			l[i] = int(l[i])
			while l[i] > 0:
				if i > d:
					found = True
					break
				l[i] -= 1
				d -= i
				ans += 1
		if found:
			break
	print(ans)


T = int(input().strip())
for i in range(T):
	(n, d) = map(int, input().strip().split())
	nums = [int(i) for i in input().strip().split()]
	index = 1
	while index < n:
		if d <= 0:
			break
		if nums[index] <= 0:
			index += 1
			continue
		if d - index >= 0:
			nums[0] += 1
			nums[index] -= 1
			d -= index
		else:
			break
	print(nums[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	res = a[0]
	for i in range(1, n):
		if d // i > a[i]:
			d -= a[i] * i
			res += a[i]
		elif d // i == a[i]:
			res += a[i]
			break
		else:
			res += d // i
			break
	print(res)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	v = [int(x) for x in input().split()]
	pos = 1
	while d > 0 and pos < n:
		if d >= pos * v[pos]:
			v[0] += v[pos]
			d -= pos * v[pos]
		else:
			aux = d // pos
			v[0] += aux
			d -= (aux + 1) * pos
		pos += 1
	print(v[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = [*map(int, input().split())]
	cnt = a[0]
	for i in range(1, n):
		cnt = min(d // i, a[i])
		a[0] += cnt
		d = d - cnt * i
		if d <= i:
			break
	print(a[0])


t = int(input())
numh = []
numd = []
for i in range(t):
	numh.append(list(map(int, input().split())))
	numd.append(list(map(int, input().split())))
for i in range(t):
	day = numh[i][1]
	val = numd[i][0]
	for j in range(1, len(numd[i])):
		if day < j * numd[i][j]:
			val += day // j
			break
		else:
			val += numd[i][j]
			day -= j * numd[i][j]
	print(val)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	count = 0
	c1 = 0
	sum = 0
	j = 1
	while sum < d and j < n:
		count = 0
		if (d - sum) // j >= l[j]:
			count = l[j]
			c1 += l[j]
		else:
			count = (d - sum) // j
			c1 += (d - sum) // j
		sum += count * j
		j += 1
	print(c1 + l[0])


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 lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()

def sieve(x):
	a = [True] * (x + 1)
	sq = floor(sqrt(x))
	for i in range(3, sq + 1, 2):
		if a[i]:
			for j in range(i * i, x + 1, i):
				a[j] = False
	if x > 1:
		p = [2]
	else:
		p = []
	for i in range(3, x + 1, 2):
		if a[i]:
			p.append(i)
	return p

def prime_factor(x):
	c = 1
	i = 0
	while p[i] * p[i] <= x:
		if not x % p[i]:
			c += 1
			while not x % p[i]:
				x //= p[i]
		i += 1
	if x > 1:
		c += 1
	return c
res = ['YES', 'NO']
for _ in range(ii()):
	(n, d) = mi()
	a = li()
	x = a[0]
	j = 1
	for i in a[1:]:
		if d < j:
			break
		p = d // j
		z = min(p, i)
		x += z
		d -= z * j
		j += 1
	print(x)


from collections import Counter, defaultdict, deque
from heapq import heapify, heappush, heappop, heappushpop
from sys import stdin
int_inp = lambda : int(stdin.readline().strip())
lst_inp = lambda : [int(i) for i in stdin.readline().strip().split(' ')]
str_inp = lambda : stdin.readline().strip()

def solve(a, n, d):
	i = 1
	while d > 0 and i < n:
		if a[i] > 0:
			a[i - 1] += 1
			a[i] -= 1
			d -= 1
			if i > 1:
				i -= 1
		else:
			i += 1
	return a[0]
for _ in range(int_inp()):
	(n, d) = lst_inp()
	a = lst_inp()
	print(solve(a, n, d))


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a0 = a[0]
	for (ind, a_i) in enumerate(a[1:]):
		ind += 1
		while a_i != 0 and d != 0:
			if d >= ind:
				a_i -= 1
				d -= ind
				a0 += 1
			else:
				break
	print(a0)


try:
	from sys import stdin, stdout
	import math
	t = int(stdin.readline())
	for _ in range(t):
		(n, d) = map(int, stdin.readline().split())
		a = [int(x) for x in stdin.readline().split()]
		if len(a) == 1:
			stdout.write(str(a[0]) + '\n')
		else:
			for i in range(1, n):
				cnt = 0
				if i == 1:
					while a[i] > 0 and d > 0:
						cnt += 1
						d -= 1
						a[i] -= 1
				else:
					while a[i] > 0 and d > i - 1:
						cnt += 1
						d -= i
						a[i] -= 1
				a[0] += cnt
			stdout.write(str(a[0]) + '\n')
except:
	pass


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = l[0]
	for i in range(1, n):
		max_ = d // i
		if l[i] <= max_:
			ans += l[i]
			d = d - i * l[i]
		else:
			ans += max_
			d = d - i * max_
	print(ans)


query = int(input())
for _ in range(query):
	(piles, vac) = map(int, input().split())
	hays = list(map(int, input().split()))
	j = 1
	while vac and j < piles:
		if hays[j] == 0:
			j += 1
		elif hays[j] * j <= vac:
			vac -= hays[j] * j
			hays[0] += hays[j]
			j += 1
		else:
			hays[j] -= 1
	print(hays[0])


T = int(input())
for _ in range(T):
	(N, D) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	ans = a[0]
	for i in range(1, N):
		move = min(a[i], D // i)
		ans += move
		D -= move * i
	print(ans)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	arr = [int(j) for j in input().split()]
	tcount = 0
	for i in range(n):
		while arr[i] != 0 and d > 0:
			if d >= i:
				arr[i] -= 1
				d -= i
				tcount += 1
			else:
				break
	print(tcount)


def haybales(a, d):
	for i in range(1, len(a)):
		while a[i] > 0 and d >= i:
			a[0] += 1
			a[i] -= 1
			d -= i
	return a[0]
t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	print(haybales(l, d))


def cow(arr, d):
	current = arr[0]
	idx = 1
	while d > 0 and idx < len(arr):
		if arr[idx] > 0:
			if idx > d:
				return current
			else:
				current += 1
				d -= idx
				arr[idx] -= 1
		else:
			idx += 1
	return current
for _ in range(int(input())):
	(n, d) = map(int, input().split())
	nums = list(map(int, input().split()))
	print(cow(nums, d))


def main(n, d, l):
	somme = l[0]
	i = 1
	test = True
	while i < n and test:
		if i > d:
			test = False
		elif l[i] > 0:
			d -= i
			somme += 1
			l[i] -= 1
		else:
			i += 1
	print(somme)
t = int(input())
for _ in range(t):
	lst = list(map(int, input().split()))
	n = lst[0]
	d = lst[1]
	l = list(map(int, input().split()))
	main(n, d, l)


from sys import stdin
for _ in range(int(stdin.readline())):
	[n, d] = [int(x) for x in stdin.readline().split()]
	arr = [int(x) for x in stdin.readline().split()]
	ptr = 1
	while n > 1 and ptr < n and (d > 0):
		while ptr < n and arr[ptr] == 0:
			ptr += 1
		if ptr >= n or ptr > d:
			break
		arr[0] += 1
		arr[ptr] -= 1
		d -= ptr
	print(arr[0])


def main():
	for _ in range(int(input())):
		(n, d) = map(int, input().split(' '))
		arr = list(map(int, input().split(' ')))
		i = 0
		r = 0
		while d > 0 and i < n - 1:
			i = i + 1
			while arr[i] != 0:
				arr[i] -= 1
				d -= i
				if d >= 0:
					r += 1
				else:
					break
		print(arr[0] + r)
main()


from collections import OrderedDict
from math import fabs
from sys import stdin
from sys import stdout
d = OrderedDict()
t = int(stdin.readline())
while t:
	t -= 1
	(n, x) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	ans = 0
	for i in range(n):
		if a[i] * i >= x:
			ans += x // i
			break
		else:
			x -= a[i] * i
			ans += a[i]
	print(ans)


def solution():
	from sys import stdin, stdout
	(_input, _print, _range, _int, _len, _str) = (stdin.readline, stdout.write, range, int, len, str)
	for _ in _range(_int(_input())):
		(n, d) = [_int(i) for i in _input().split()]
		arr = [_int(i) for i in _input().split()]
		current = 1
		while d > 0 and current < n:
			if d >= arr[current] * current:
				arr[0] += arr[current]
				d -= arr[current] * current
			else:
				temp = d // current
				arr[0] += temp
				d -= temp * current
			current += 1
		print(arr[0])
solution()


import bisect

def solution():
	(n, d) = [int(x) for x in input().strip().split()]
	a = [int(x) for x in input().strip().split()]
	res = a[0]
	for i in range(1, len(a)):
		while a[i] and d >= i:
			a[i] -= 1
			d -= i
			res += 1
	print(res)

def main():
	T = int(input().strip())
	for _ in range(T):
		solution()
main()


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, d) = R()
	r = i = 0
	for x in R():
		m = min(d, i * x)
		r += m // i if i else x
		d -= m
		i += 1
	print(r)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(1, n):
		p = min(d, i * l[i])
		d = d - p
		l[0] = l[0] + p // i
	print(l[0])


def Input():
	tem = input().split()
	ans = []
	for it in tem:
		ans.append(int(it))
	return ans
from collections import Counter
T = Input()[0]
for tt in range(T):
	(n, m) = Input()
	a = Input()
	if n == 1:
		print(a[0])
	else:
		ans = a[0]
		for i in range(1, n):
			tem = m // i
			if a[i] < tem:
				m -= a[i] * i
				ans += a[i]
			else:
				ans += tem
				break
		print(ans)


n = int(input())
for _ in range(n):
	(dlina, d) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	for i in range(1, dlina):
		while arr[i] > 0 and d >= i:
			arr[0] += 1
			d -= i
			arr[i] -= 1
	print(arr[0])


def checker(n, d, lst):
	result = lst[0]
	for i in range(1, n):
		if lst[i] * i <= d:
			d -= lst[i] * i
			result += lst[i]
		else:
			result += d // i
			break
	return result
for _ in range(int(input())):
	(N, D) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	print(checker(N, D, a))


t = int(input())
for k in range(t):
	(n, d) = map(int, input().split())
	mas = list(map(int, input().split()))
	ans = mas[0]
	for i in range(1, n):
		z = min(mas[i], d // i)
		ans += z
		d -= z * i
	print(ans)


t = int(input())
z = []
for i in range(0, t):
	(n, d) = input().split()
	n = int(n)
	d = int(d)
	b = list(map(int, input().strip().split()))[:n]
	i = 1
	while d > 0:
		if i >= len(b):
			break
		if b[i] != 0:
			k = b[i] * i
			if k <= d:
				b[0] += k // i
				d = d - k
			elif d < k:
				b[0] += d // i
				d = 0
		i = i + 1
	z.append(b[0])
for i in z:
	print(i)


def hayebale(n, d, l):
	c = 0
	for i in range(1, n):
		if c > d:
			break
		while l[i] > 0:
			c += i
			if c <= d:
				l[i] -= 1
				l[0] += 1
			else:
				break
	print(l[0])
q = int(input())
for o in range(q):
	z = input().split()
	n = int(z[0])
	d = int(z[1])
	hayebale(n, d, list(map(int, input().split())))


import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2 ** 62 - 1

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

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

def read_float():
	return float(input())

def read_float_n():
	return list(map(float, input().split()))

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

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

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

@mt
def slv(N, D, A):
	for (i, a) in enumerate(A):
		if i == 0:
			continue
		if a * i < D:
			A[0] += a
			D -= a * i
		else:
			A[0] += D // i
			D = 0
			break
	return A[0]

def main():
	T = read_int()
	for _ in range(T):
		(N, D) = read_int_n()
		A = read_int_n()
		print(slv(N, D, A))
main()


import sys
t = int(sys.stdin.readline().strip())
for i in range(t):
	(n, d) = map(int, sys.stdin.readline().strip().split())
	a = list(map(int, sys.stdin.readline().strip().split()))
	kokku = a[0]
	koht = 1
	paev = 0
	while koht <= d - paev and koht < n:
		if a[koht] > 0:
			aeg = min(koht * a[koht], (d - paev) // koht * koht)
			kokku += aeg / koht
			paev += aeg
		koht += 1
	sys.stdout.write(str(int(kokku)) + '\n')


t = int(input())
for r in range(t):
	(n, d) = list(map(int, input().split()))
	mylist = list(map(int, input().split()))
	for nd in range(d):
		for pile in range(n - 1):
			if mylist[pile + 1] > 0:
				mylist[pile] += 1
				mylist[pile + 1] -= 1
				break
	print(mylist[0])


from sys import stdin

def func(arr, d):
	count = arr[0]
	i = 1
	while i < len(arr) and d > 0:
		x = min(arr[i] * i, d)
		count += x // i
		d -= x
		i += 1
	return count
for _ in range(int(stdin.readline())):
	(n, d) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	print(func(arr, d))


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def solve():
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = a[0]
	for i in range(1, n):
		j = min(d // i, a[i])
		ans += j
		d -= i * j
	print(ans)
t = int(input())
for i in range(t):
	solve()


import sys
import math

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

def data_input():
	return [int(x) for x in fast_input().split()]

def binary_search(array, x):
	(left, right) = (-1, len(array))
	while left + 1 != right:
		middle = (left + right) // 2
		if array[middle] >= x:
			right = middle
		elif array[middle] < x:
			left = middle
	return right

def solve_of_problem():
	(n, d) = data_input()
	data = data_input()
	if n > 1:
		summ = data[0]
		data[0] = 0
		for i in range(1, n):
			if data[i] * i + data[i - 1] < d:
				summ += data[i]
				data[i] = data[i] * i + data[i - 1]
			else:
				print(summ + min((d - data[i - 1]) // i, data[i]))
				return
		print(summ)
	else:
		print(data[0])
	return
for ______ in range(int(fast_input())):
	solve_of_problem()


import math
for _ in range(int(input())):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	a = l[0]
	for i in range(1, n):
		b = min(l[i], d // i)
		a += b
		d -= b * i
		if d <= 0:
			break
	print(a)


import math
for _ in range(int(input())):
	(w, s) = map(int, input().split())
	a = list(map(int, input().split()))
	wasd = 0
	m = 1
	for m in range(1, len(a)):
		if a[m] == 0:
			continue
		if a[m] * m <= s:
			wasd += a[m]
			s -= a[m] * m
		else:
			wasd += math.floor(s / m)
			break
	print(a[0] + wasd)


def solve(d, stogs):
	number = 0
	local = stogs[0]
	for (j, num) in enumerate(stogs[1:]):
		for z in range(num):
			local += 1
			number += j + 1
			if number > d:
				return local - 1
	return local
for i in range(int(input())):
	(n, d) = map(int, input().split())
	stogs = list(map(int, input().split()))
	print(solve(d, stogs))


from sys import stdin

def solve(a, d):
	(i, N) = (0, len(a))
	while d > 0:
		i = 2
		while i < N and a[1] == 0 and (d > 0):
			if a[i] > 0:
				a[1] += 1
				d -= i - 1
				a[i] -= 1
			i += 1
		if d > 0:
			d -= 1
			if N > 1 and a[1] > 0:
				(a[1], a[0]) = (a[1] - 1, a[0] + 1)
	return a[0]

def main():
	t = int(stdin.readline().strip())
	for _ in range(t):
		(n, d) = map(int, stdin.readline().strip().split())
		a = [int(x) for x in stdin.readline().strip().split()]
		print(solve(a, d))
main()


t = int(input())
for i in range(t):
	(n, d) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	day = 0
	k = 1
	while day <= d and k < n:
		if a[k] == 0:
			k = k + 1
		elif d - day >= k:
			day = day + k
			a[0] = a[0] + 1
			a[k] = a[k] - 1
		else:
			break
	print(a[0])


import sys
input = sys.stdin.readline
for l in range(int(input())):
	(n, d) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	ans = a[0]
	for j in range(1, len(a)):
		l = j * a[j]
		if l <= d:
			ans = ans + a[j]
			d = d - l
		else:
			l = int(d / j)
			d = d - l * j
			ans = ans + l
	print(ans)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	cnt = 0
	for i in range(1, n):
		cnt = i
		while l[i] > 0 and d > 0:
			d = d - cnt
			if d >= 0:
				l[0] += 1
			l[i] -= 1
		if d < 0:
			break
	print(l[0])


def func(pile, day):
	ret = pile[0]
	for i in range(1, len(pile)):
		cost = i * pile[i]
		if day >= cost:
			ret += pile[i]
			day -= cost
		else:
			for j in range(1, pile[i] + 1):
				if i * j > day:
					cost = i * (j - 1)
					ret += j - 1
					day -= cost
					break
	return ret
t = int(input())
piles = []
days = []
for _ in range(t):
	tmp = list(map(int, input().split()))
	num_piles = tmp[0]
	days.append(tmp[1])
	tmp = list(map(int, input().split()))
	piles.append(tmp)
for i in range(t):
	print(func(piles[i], days[i]))


x = int(input())
for i in range(x):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	a = l[0]
	t = 0
	for i in range(1, len(l)):
		if d <= l[i] * i:
			a += d // i
			d -= d // i
			break
		else:
			a += l[i]
			d -= l[i] * i
	print(a)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	ctr = 0
	for j in range(1, len(l)):
		while l[j] > 0:
			ctr += j
			if ctr > b:
				break
			else:
				l[j] -= 1
				l[0] += 1
	print(l[0])


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(n, d) = map(int, sys.stdin.readline().split())
	nums = list(map(int, sys.stdin.readline().split()))
	answ = nums[0]
	for i in range(1, n):
		if d == 0:
			break
		pile = min(d // i, nums[i])
		answ += pile
		d -= pile * i
	print(answ)


from operator import itemgetter
from collections import Counter

def solve(n, d, a):
	ans = a[0]
	for i in range(1, n):
		b = min(a[i], d // i)
		ans += b
		d = d - b * i
	print(ans)

def main():
	t = int(input())
	for i in range(t):
		(n, d) = map(int, input().split())
		a = list(map(int, list(input().split())))
		solve(n, d, a)
main()


import math

def main():
	y = list(map(int, str(input()).split(' ')))
	z = list(map(int, str(input()).split(' ')))
	i = 1
	while i < len(z):
		if y[1] > 0:
			if z[i] * i <= y[1]:
				z[0] += z[i]
				y[1] -= z[i] * i
			else:
				z[0] = z[0] + math.floor(y[1] / i)
				y[1] = y[1] - math.floor(y[1] / i) * i
			i += 1
		else:
			i += 1
			break
	print(z[0])
x = int(input())
for _ in range(x):
	main()


t = int(input())
while t > 0:
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	res = l[0]
	for i in range(1, n):
		avail = min(d // i, l[i])
		res += avail
		d -= avail * i
	print(res)
	t -= 1


tt = int(input())
while tt > 0:
	(n, days) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(1, n):
		time = min(days, a[i] * i)
		shift = time // i
		ans += shift
		days -= min(days, a[i] * i)
	ans += a[0]
	print(ans)
	tt -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(1, n):
		while k > 0 and arr[i] > 0:
			arr[0] += 1
			arr[i] -= 1
			k -= i
		if k < 0:
			arr[0] -= 1
			break
		elif k == 0:
			break
	print(arr[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	al = list(map(int, input().split()))
	ans = 0
	for (idx, a) in enumerate(al):
		if idx * a <= d:
			ans += a
			d -= idx * a
		else:
			k = d // idx
			ans += k
			break
	print(ans)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	l = [int(i) for i in input().split()]
	for j in range(1, len(l)):
		x = min(l[j], d // j)
		d -= x * j
		if d < 0:
			break
		else:
			l[0] += x
	print(l[0])


from collections import defaultdict

def one():
	return int(input())

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

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

def st():
	return input()
for _ in range(one()):
	(n, d) = more()
	l = lis()
	count = l[0]
	for i in range(1, len(l)):
		c = min(l[i], d // i)
		count += c
		d -= c * i
		if d == 0:
			break
	print(count)


q = int(input())
for x in range(q):
	(n, d) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	res = l[0]
	i = 1
	j = 0
	while d > 0 and i < len(l):
		if d >= l[i] * i:
			res += l[i]
			d -= l[i] * i
		else:
			res += int(d / i)
			break
		i += 1
	print(res)


def calc(days: int, pilesRow: list):
	realDays: int = days
	for i in range(1, len(pilesRow)):
		value: int = pilesRow[i]
		distance: int = i
		fullMoveDays: int = distance * value
		doMovePile: int
		doMoveDays: int
		if value == 0:
			continue
		elif days == 0 or realDays < i:
			break
		if fullMoveDays > days:
			doMovePile = value * days // fullMoveDays
			doMoveDays = distance * doMovePile
			pilesRow[0] += doMovePile
			pilesRow[distance] -= doMovePile
			days -= doMoveDays
		elif fullMoveDays <= days:
			doMovePile = value
			doMoveDays = fullMoveDays
			pilesRow[0] += doMovePile
			pilesRow[distance] -= doMovePile
			days -= doMoveDays
	return pilesRow[0]

def main():
	n: int = int(input())
	for i in range(n):
		(_, d) = map(int, input().strip().split())
		pilesRow: list = list(map(int, input().strip().split()))
		print(calc(d, pilesRow))
main()


t = int(input())
while t:
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 1
	while b > 0 and c != len(l):
		if l[c] != 0:
			if b - c < 0:
				break
			l[0] += 1
			l[c] -= 1
			b -= c
		else:
			c += 1
	print(l[0])
	t -= 1


import pdb
t = int(input())
for i in range(0, t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for j in range(1, len(a)):
		a[0] = a[0] + min(d // j, a[j])
		d -= j * a[j]
		if d < 0:
			break
	print(a[0])


t = int(input())
while t:
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	res = l[0]
	for i in range(1, n):
		if d == 0:
			break
		h = d // i
		a = min(h, l[i])
		res += a
		l[i] -= a
		d -= i * a
	print(res)
	t -= 1


import sys
from math import floor, ceil
import bisect
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

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

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

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

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

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

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 30
MOD = 10 ** 7
for _ in range(int(ri())):
	(n, d) = Ri()
	a = Ri()
	for i in range(1, n):
		if i * a[i] <= d:
			a[0] += a[i]
			d -= i * a[i]
		else:
			a[0] += d // i
			d = 0
			break
	print(a[0])


def main(t):
	while t:
		(n, d) = map(int, input().split())
		haybale_list = list(map(int, input().split()))
		count = 0
		multiplier = 1
		for haybale in haybale_list[1:]:
			while haybale * multiplier > d:
				haybale -= 1
			count += haybale
			d -= haybale * multiplier
			multiplier += 1
			if multiplier > d:
				break
		count += haybale_list[0]
		print(count)
		t -= 1
	return
trials = int(input())
main(trials)


t = int(input())
ans = []
for i in range(t):
	day = 0
	p = list(map(int, input().split()))
	(n, d) = p
	flag = False
	num = list(map(int, input().split()))
	for k in range(1, n):
		while num[k] > 0 and day + k <= d:
			num[0] += 1
			num[k] -= 1
			day += k
			if day + k > d:
				flag = True
				break
		if flag:
			break
	ans.append(num[0])
for j in ans:
	print(j)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	p = list(map(int, input().split()))
	f = p[0]
	i = 1
	while i < n:
		k = min(p[i], d // i)
		f += k
		d -= k * i
		i += 1
	print(f)


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10 ** 9 + 7
t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	if len(a) == 1:
		print(a[0])
		continue
	total = 0
	for j in range(1, n):
		if d <= 0:
			break
		if a[j] >= 1:
			if j * a[j] <= d:
				total += a[j]
				d -= j * a[j]
			else:
				total += d // j
				break
	print(a[0] + total)


t = int(input())
for i in range(t):
	num_input = input()
	num_input = num_input.split(' ')
	n = int(num_input[0])
	d = int(num_input[1])
	num_input = input()
	num_input = num_input.split(' ')
	a = []
	a.append(int(num_input[0]))
	for j in range(1, n):
		a.append(int(num_input[j]))
		while d - j >= 0 and a[j] > 0:
			d -= j
			a[0] += 1
			a[j] -= 1
	print(a[0])


t = int(input())
for ii in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	ans = l[0]
	i = 1
	while d > 0 and i < n:
		if l[i] * i <= d:
			ans += l[i]
			d -= l[i] * i
			i += 1
		else:
			ans += d // i
			d = 0
	print(ans)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	t = 0
	a = 0
	for i in range(1, n):
		if l[i] * i + t <= d:
			t += l[i] * i
			a += l[i]
		else:
			for z in range(l[i]):
				if t + i <= d:
					t += i
					a += 1
				else:
					break
	print(l[0] + a)


has_tests = True

def solve_case():
	(n, days) = get([int])
	piles = get([int])
	i = 1
	ans = piles[0]
	while days // i > 0 and i < n:
		if piles[i] == 0:
			i += 1
			continue
		stacks = min(piles[i], days // i)
		ans += stacks
		days -= stacks * i
		i += 1
	return ans

def get(x, times=None):
	if times is not None:
		return [get(x, times=None) for _ in range(times)]
	if isinstance(x, list):
		return list(map(x[0], input().strip().split()))
	return x(input().strip())
if has_tests:
	for _ in range(get(int)):
		print(solve_case())
else:
	solve_case()


sets = int(input())
answers = []
for _ in range(sets):
	(n, d) = list(map(int, input().split()))
	stacks = list(map(int, input().split()))
	for _ in range(d):
		for i in range(1, n):
			if stacks[i] > 0:
				stacks[i] -= 1
				stacks[i - 1] += 1
				break
	answers.append(stacks[0])
for ans in answers:
	print(ans)


T = int(input())
for i in range(T):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = arr[0]
	for i in range(1, n):
		ans += min(int(d / i), arr[i])
		d -= min(d, arr[i] * i)
	print(ans)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	z = l[0]
	for i in range(1, len(l)):
		if b >= l[i] * i:
			b -= l[i] * i
			z += l[i]
		else:
			z += b // i
			break
	print(z)


for a in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	i = 1
	while k > 0 and i < n:
		c = min(k // i, l[i])
		if c != 0:
			l[0] += c
			k -= c * i
		i += 1
		if k < i:
			break
	print(l[0])


from collections import *
te = int(input())
for y in range(te):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(d):
		for j in range(1, n):
			if a[j] != 0:
				a[j - 1] += 1
				a[j] -= 1
				break
	print(a[0])


t = int(input())
while t > 0:
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 1
	while i < n:
		if a[i] >= d // i:
			a[0] += d // i
			break
		else:
			a[0] += a[i]
			d -= a[i] * i
		i += 1
	print(a[0])
	t -= 1


t = int(input())
while t != 0:
	(n, d) = map(int, input().split())
	A = map(int, input().split())
	B = list(A)

	def check():
		global d
		i = 1
		index = B[0]
		while d > 0 and i < n:
			while B[i] == 0 and i < n:
				i += 1
				if i == n:
					return index
			B[i] -= 1
			index += 1
			d -= i
		return index
	y = check()
	if d < 0:
		print(y - 1)
	else:
		print(y)
	t -= 1


def optimize(n, d, a):
	if n > 1:
		for i in range(d):
			if a[1] > 0:
				shift_hay_bale(a, 0)
			else:
				for i in range(1, n - 1):
					if a[i + 1] > a[i]:
						shift_hay_bale(a, i)
						break
	return a[0]

def shift_hay_bale(a, i):
	a[i + 1] -= 1
	a[i] += 1
t = int(input())
o = list()
for i in range(t):
	(n, d) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	o.append(optimize(n, d, a))
print(*o, sep='\n')


def customer(l, d, n):
	total = l[0]
	for i in range(1, n):
		if d - l[i] * i >= 0:
			total += l[i]
			d -= l[i] * i
		else:
			total += d // i
			return total
	return total
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	queries = list(map(int, input().split()))
	print(customer(queries, m, n))


t = int(input())
while t:
	t = t - 1
	(n, d) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	maxi = arr[0]
	for i in range(1, n):
		if d > arr[i] * i:
			maxi = maxi + arr[i]
			d = d - arr[i] * i
		else:
			k = d // i
			maxi = maxi + k
			d = d - k * i
	print(maxi)


for _ in range(int(input())):
	(n, d) = [int(i) for i in input().split()]
	(ans, cont) = (0, 0)
	lista = [int(i) for i in input().split()]
	for x in lista:
		if cont * x > d:
			ans += d // cont
			break
		d -= cont * x
		ans += x
		cont += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, d) = tuple(map(int, input().split()))
	ar = list(map(int, input().split()))
	count = ar[0]
	for i in range(1, n):
		cur = i * ar[i]
		if d >= cur:
			count += ar[i]
			d -= cur
		else:
			count += int(d // i)
			d = 0
		if d == 0:
			break
	print(count)


t = int(input())
for _ in range(t):
	(n, d) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	i = 1
	s = 0
	while d > 0 and i < n:
		dif = a[i] * i
		if d >= dif:
			d = d - dif
			s = s + a[i]
			i = i + 1
		elif d >= i:
			d = d - i
			s = s + 1
		else:
			break
	print(a[0] + s)


test_cases = int(input())
for i in range(test_cases):
	(n, d) = input().split()
	(n, d) = (int(n), int(d))
	hay_bales = input().split()
	hay_bales = [int(x) for x in hay_bales]
	ptr = 1
	while ptr < len(hay_bales):
		if hay_bales[ptr] > 0:
			if d >= ptr:
				hay_bales[ptr] -= 1
				hay_bales[0] += 1
				d -= ptr
			else:
				break
		else:
			ptr += 1
	print(hay_bales[0])


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	for j in range(1, a):
		if l[j] == 0:
			continue
		else:
			for k in range(1, l[j] + 1):
				if j <= b:
					b -= j
					l[0] += 1
	print(l[0])


for _ in range(int(input())):
	(n, d) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	for i in range(1, len(arr)):
		if d <= 0:
			break
		while arr[i] > 0 and d - i >= 0:
			arr[0] += 1
			arr[i] -= 1
			d -= i
	print(arr[0])


n = int(input())
for i in range(n):
	li = [int(i) for i in input().split()]
	li1 = [int(i) for i in input().split()]
	for i in range(li[1]):
		for j in range(1, li[0]):
			if li1[j] == 0:
				continue
			else:
				li1[j] -= 1
				li1[j - 1] += 1
				break
	print(li1[0])


t = int(input())
for query in range(t):
	nd = input().split()
	piles = int(nd[0])
	days = int(nd[1])
	mylist = input().split()
	for x in range(piles):
		mylist[x] = int(mylist[x])
	for x in range(1, piles):
		while days >= x and mylist[x] > 0:
			days = days - x
			mylist[x] = mylist[x] - 1
			mylist[0] = mylist[0] + 1
	print(mylist[0])


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = a[0]
	now = 1
	while d >= now and now < n:
		k = min(a[now], d // now)
		ans += k
		d -= k * now
		now += 1
	print(ans)


from math import ceil, sqrt, floor
n = int(input())
for i in range(n):
	(nbPiles, days) = map(int, input().split())
	piles = list(map(int, input().split()))
	for pile in range(1, nbPiles):
		if days <= 0:
			break
		piles[0] += min(days // pile, piles[pile])
		days -= pile * min(days // pile, piles[pile])
	print(piles[0])


cases = int(input())
for _ in range(cases):
	(n, d) = [int(i) for i in input().split(' ')]
	piles = [int(i) for i in input().split(' ')]
	count = piles[0]
	for i in range(1, n):
		if d // i == 0:
			break
		move = min(piles[i], d // i)
		count += move
		d -= move * i
	print(count)


T = int(input())
for _ in range(T):
	(n, d) = [int(x) for x in input().split()]
	hay = [int(x) for x in input().split()]
	i = 1
	while d > 0 and i < n:
		if hay[i] > 0:
			if d >= i:
				d -= i
				hay[i] -= 1
				hay[0] += 1
			else:
				d = 0
		else:
			i += 1
	print(hay[0])


import string

def main():
	(n, d) = map(int, input().split())
	lst = list(map(int, input().split()))
	amm = 0
	for i in range(1, len(lst)):
		if lst[i] > 0 and d > 0:
			if i <= d and lst[i] > 0:
				moves = min(d // i, lst[i])
				amm += moves
				d -= moves * i
			else:
				break
	print(amm + lst[0])
t = int(input())
for i in range(t):
	main()


t = int(input())
for _ in range(0, t):
	(n, d) = map(int, input().split())
	A = list(map(int, input().split()))
	q = A[0]
	y = d
	for i in range(1, n):
		if y >= i * A[i]:
			y -= i * A[i]
			q += A[i]
		elif y > 0:
			x = y // i
			y -= i * x
			q += x
		else:
			break
	print(q)


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(n, d) = map(int, input().split())
	mas = list(map(int, input().split()))
	ans = 0
	k = 0
	for i in range(1, n):
		if d >= i * mas[i]:
			d -= mas[i] * i
			mas[0] += mas[i]
		else:
			mas[0] += d // i
			break
	print(mas[0])


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(1, x):
		a[0] = a[0] + min(y // i, a[i])
		y = y - min(y // i, a[i]) * i
		if y <= 0:
			break
	print(a[0])


t = int(input())
for g in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	d1 = 0
	c = 0
	for i in range(1, n):
		a[i] = a[i] * i
	for i in range(1, n):
		d1 = d1 + a[i] / i
		c = c + a[i]
		if c > d:
			j = i
			d1 = d1 - int(a[j] / j)
			c = c - a[j]
			c = c + j
			for u in range(1, int(a[j] / j) + 1):
				if c <= d:
					c = c + 1 * j
					d1 = d1 + 1
				else:
					break
			break
	print(int(d1 + a[0]))


def solve():
	(n, d) = map(int, input().split())
	h = list(map(int, input().split()))
	now = 0
	res = 0
	for i in range(len(h)):
		if i * h[i] + now <= d:
			res += h[i]
			now += i * h[i]
		else:
			res += (d - now) // i
			print(res)
			return
	print(res)
	return
tests = int(input())
for _ in range(tests):
	solve()


t = int(input())
for case in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for _ in range(d):
		for i in range(1, n):
			if a[i] > 0:
				a[i - 1] += 1
				a[i] -= 1
				break
	print(a[0])


def solve():
	(n, d) = map(int, input().split())
	li = list(map(int, input().split()))
	while d:
		for i in range(1, n):
			if li[i] > 0:
				li[i] -= 1
				li[i - 1] += 1
				break
		d -= 1
	print(li[0])
t = int(input())
for _ in range(t):
	solve()


import sys
queries = int(sys.stdin.readline())
for query in range(queries):
	(count, days) = map(int, sys.stdin.readline().strip().split())
	hay = sys.stdin.readline().strip().split()
	pos = 1
	answer = int(hay[0])
	while pos < count:
		canReplace = days // pos
		if canReplace == 0:
			break
		else:
			add = min(int(hay[pos]), canReplace)
			answer += add
			days -= add * pos
		pos += 1
	print(answer)


import sys
t = int(input())
while t:
	(n, d) = map(int, sys.stdin.readline().split())
	a = list(map(int, input().split()))
	k = a[0]
	i = 1
	while d >= 1:
		if i <= n - 1:
			if a[i] != 0:
				x = d // i
				if x >= a[i]:
					k = k + a[i]
					d = d - a[i] * i
				else:
					k = k + x
					d = d - x * i
					break
			i = i + 1
		else:
			break
	print(k)
	t = t - 1


def solve(N, D, A):
	count = A[0]
	for i in range(1, N):
		for j in range(A[i]):
			if D >= i:
				D -= i
				count += 1
	return count
(T,) = map(int, input().split())
for t in range(T):
	(N, D) = map(int, input().split())
	A = [int(x) for x in input().split()]
	ans = solve(N, D, A)
	print(ans)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	m = arr[0]
	for i in range(1, n):
		q = min(arr[i], d // i)
		a = q * i
		d -= a
		m += q
	print(m)


for t in range(int(input())):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	for i in range(1, n):
		check = min(d // i, arr[i])
		d -= check * i
		arr[0] += check
	print(arr[0])


for i in range(int(input())):
	(n, d) = map(int, input().split())
	x = [int(x) for x in input().split()]
	for j in range(1, n):
		if x[j] != 0:
			if x[j] * j <= d:
				x[0] = x[0] + x[j]
				d = d - x[j] * j
			else:
				while d >= j and x[j] != 0:
					x[0] = x[0] + 1
					d = d - j
					x[j] = x[j] - 1
	print(x[0])


def solve(cow, days):
	a1 = cow[0]
	for x in range(1, len(cow)):
		if x > days:
			return a1
		if cow[x] != 0:
			moves = days // x
			interim = moves if moves <= cow[x] else cow[x]
			a1 += interim
			days -= x * interim
	return a1
tests = int(input())
for k in range(tests):
	(bales, days) = map(int, input().split())
	farmer = list(map(int, input().split()))
	print(solve(farmer, days))


t = int(input(''))
for _ in range(t):
	[n, d] = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	ans = arr[0]
	for i in range(1, n):
		baki = d
		lagbe = arr[i] * i
		jabe = min(baki, lagbe)
		ans += jabe // i
		d -= jabe
		if d < 0:
			break
	print(ans)


t = int(input())
a = []
for i in range(t):
	(b, c) = map(int, input().split())
	d = list(map(int, input().split()))
	a.append([d, c])
for i in a:
	k = i[0]
	d = i[1]
	sum = k[0]
	for j in range(1, len(k)):
		while k[j] > 0:
			k[j] += -1
			d += -j
			if d < 0:
				break
			else:
				sum += 1
		if d < 0:
			break
	print(sum)


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

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

def string_list():
	return list(input())

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

def binaryToDecimal(n):
	return int(n, 2)

def solve():
	(n, d) = num_input()
	arr = list_input()
	ans = arr[0]
	for i in range(1, n):
		if arr[i] > 0:
			if d >= i:
				if arr[i] >= d // i:
					ans += d // i
					d -= i * (d // i)
				else:
					ans += arr[i]
					d -= i * arr[i]
			else:
				break
	print(ans)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	(n, day) = map(int, input().split())
	haystecks = list(map(int, input().split()))
	iter = 1
	while day > 0:
		if n > 1:
			try:
				if haystecks[iter] > 0:
					haystecks[iter - 1] += 1
					haystecks[iter] -= 1
					day -= 1
					iter = 1
				else:
					iter += 1
			except:
				break
		else:
			break
	print(haystecks[0])


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, d) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	if n == 1:
		print(a[0])
		continue
	i = 1
	while d > 0 and i < len(a):
		a[0] = a[0] + max(min(a[i], d // i), 0)
		d -= a[i] * i
		i += 1
	print(a[0])


t = int(input())
for I in range(t):
	(n, d) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	for i in range(1, len(a)):
		if d <= 0:
			break
		can_t = d // i
		if a[i] >= can_t:
			a[0] += can_t
			d = 0
		else:
			a[0] += a[i]
			d -= a[i] * i
	print(a[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	if len(l) == 1:
		print(l[0])
	else:
		for i in range(1, len(l)):
			mi = min(i * l[i], d)
			d = d - mi
			l[0] = l[0] + mi // i
		print(l[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	l = [int(x) for x in input().split()]
	max = l[0]
	if n == 1:
		print(max)
	else:
		i = 1
		while d > 0:
			if l[i] > 0:
				l[i] -= 1
				d -= i
				if d >= 0:
					max += 1
			else:
				i += 1
				if i == n:
					break
		print(max)


import sys, math
input = sys.stdin.readline

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

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

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

def invr():
	return map(int, input().split())
t = 1
t = inp()
for tt in range(t):
	(n, d) = invr()
	a = inlt()
	c = a[0]
	for i in range(1, len(a)):
		q = min(a[i], d // i)
		d = d - q * i
		c = c + q
		if d <= 0:
			break
	print(c)


T = int(input())
for i in range(T):
	c = 0
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	i = 1
	while m > 0 and i < n:
		x = m - i * l[i]
		if x <= 0:
			x = m // i
			c = c + x
			break
		else:
			m = x
			c = c + l[i]
		i = i + 1
	print(c + l[0])


import math as mt
import bisect
import sys
input = sys.stdin.readline
t = int(input())
import collections
import heapq
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve(n, d, l):
	ans = l[0]
	for i in range(1, n):
		while d - i >= 0 and l[i] > 0:
			l[i] -= 1
			d -= i
			ans += 1
	return ans
for _ in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	print(solve(n, d, l))


n = int(input())

def main():
	temp = input().split()
	num = int(temp[0])
	day = int(temp[1])
	temp = input().split()
	arr = list(map(int, temp))
	for i in range(1, num):
		if day < i:
			break
		if arr[i] == 0:
			continue
		temp = min(day // i, arr[i])
		arr[0] = arr[0] + temp
		day = day - temp * i
		arr[i] = arr[i] = temp
	return arr[0]
for _ in range(n):
	print(main())


(t,) = map(int, input().split())
for _ in range(t):
	(N, M) = map(int, input().split())
	A = list(map(int, input().split()))
	r = 0
	for (i, a) in enumerate(A):
		if M >= a * i:
			tm = a
		else:
			tm = M // i
		r += tm
		M -= i * tm
	print(r)


t = int(input())
while t:
	readline = input().split()
	n = int(readline[0])
	d = int(readline[1])
	readline = input().split()
	ans = 0
	for i in range(n):
		a = int(readline[i])
		if i == 0:
			ans += a
			continue
		move = min(a, d // i)
		ans += move
		d -= move * i
	print(ans)
	t -= 1


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time

def I():
	return int(input())

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

def S():
	return input()

def MS():
	return map(str, input().split())

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

def LI_():
	return [int(i) - 1 for i in input().split()]

def StoI():
	return [ord(i) - 97 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

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

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = {False: 'No', True: 'Yes'}
MOD = 10 ** 9 + 7
inf = float('inf')
IINF = 10 ** 10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False

def solve(T):
	(n, d) = MI()
	a = LI()
	ans = a[0]
	cur = 0
	for i in range(1, n):
		if a[i] > 0:
			for j in range(a[i]):
				if cur + i <= d:
					ans += 1
					cur += i
		if cur >= d:
			break
	print(ans)

def main():
	T = I()
	for i in range(T):
		solve(T)
main()


tests = int(input())
for _ in range(tests):
	(n, d) = list(map(int, input().split()))
	inp = list(map(int, input().split()))
	ans = inp[0]
	i = 1
	while i < len(inp):
		d -= inp[i] * i
		if d < 0:
			d += inp[i] * i
			ans += d // i
			break
		else:
			ans = ans + inp[i]
		i += 1
	print(ans)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input().strip()
mod = 1000000007
for i in range(I()):
	(n, d) = li()
	a = li()
	for i in range(1, n):
		if d >= a[i] * i:
			a[0] += a[i]
			d -= a[i] * i
		else:
			a[0] += d // i
			break
	print(a[0])


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


t = int(input())
for i in range(t):
	(n, d) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	pile = 1
	while d > 0 and pile < n:
		ways = d // pile
		if ways < 0:
			break
		elif ways >= a[pile]:
			a[0] = a[0] + a[pile]
			d = d - a[pile] * pile
			pile += 1
		else:
			a[0] = a[0] + ways
			break
	print(a[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 1
	x = 1
	while d >= i and x < n:
		if a[i] > 0:
			h = int(d / x)
			if a[i] >= h:
				a[0] = a[0] + h
				d = d - d
			else:
				a[0] = a[0] + a[i]
				d = d - x * a[i]
		x = x + 1
		i = i + 1
	print(a[0])


from sys import stdin, gettrace
if not gettrace():

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

def main():

	def solve():
		(n, d) = map(int, input().split())
		aa = [int(a) for a in input().split()]
		sum = aa[0]
		for i in range(1, n):
			sum += min(aa[i], d // i)
			d -= aa[i] * i
			if d < i:
				break
		print(sum)
	q = int(input())
	for _ in range(q):
		solve()
main()


for i in range(int(input())):
	(n, d) = map(int, input().split())
	a = [*map(int, input().split())]
	j = 1
	ans = a[0]
	while d > 0 and j < n:
		k = min(d, a[j] * j) // j
		ans += k
		d -= k * j
		j += 1
	print(ans)


cases = int(input())
while cases:
	cases -= 1
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = arr[0]
	sm = sum(arr)
	i = 1
	while d > 0 and ans != sm and (i < n):
		piles = arr[i]
		while piles > 0 and d >= i:
			ans += 1
			piles -= 1
			d -= i
		i += 1
	print(ans)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	sume = arr[0]
	count = d
	for j in range(0, d):
		for k in range(1, len(arr)):
			if arr[k] > 0:
				arr[k - 1] += 1
				arr[k] -= 1
				break
	print(arr[0])


from sys import stdin, stdout

def solve(bales, d):
	for i in range(1, len(bales)):
		move = min(bales[i], d // i)
		bales[0] += move
		d -= move * i
	stdout.write(f'{bales[0]}\n')
	return None
t = int(stdin.readline())
for _ in range(t):
	(n, d) = map(int, stdin.readline().split())
	bales = list(map(int, stdin.readline().split()))
	solve(bales, d)


def solve():
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(d):
		for j in range(1, n):
			if a[j] > 0:
				a[j] -= 1
				a[j - 1] += 1
				break
	print(a[0])
t = int(input())
for _ in range(t):
	solve()


for i in range(int(input())):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	for j in range(1, n, 1):
		x = d // j
		l[0] += min(x, l[j])
		d -= min(x, l[j]) * j
	print(l[0])


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	daysleft = k
	for i in range(1, n):
		if daysleft == 0:
			break
		if a[i] * i > daysleft:
			a[i] -= daysleft
			a[0] += daysleft // i
			daysleft = 0
		else:
			a[0] += a[i]
			daysleft -= a[i] * i
			a[i] = 0
	print(a[0])


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(t,) = I()
while t:
	t -= 1
	(n, d) = I()
	a = I()
	i = 1
	while i < n and d:
		while a[i] and d >= i:
			d -= i
			a[0] += 1
			a[i] -= 1
		i += 1
	print(a[0])


for m in range(int(input())):
	nd = list(map(int, input().split()))
	a = list(map(int, input().split()))
	summa = 0
	for k in a:
		summa += k
	while nd[1] > 0 and a[0] != summa:
		for i in range(1, nd[0]):
			if a[i] != 0:
				a[i - 1] += 1
				a[i] -= 1
				nd[1] -= 1
				break
	print(a[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	res = a[0]
	for i in range(1, n):
		max_moves = d // i
		moves = min(max_moves, a[i])
		res += moves
		d -= moves * i
		if max_moves <= a[i]:
			break
	print(res)


for __ in range(int(input())):
	(n, d) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	while d:
		for i in range(1, len(arr), 1):
			if arr[i] > 0:
				arr[i] -= 1
				arr[i - 1] += 1
				break
		d -= 1
	print(arr[0])


__ = int(input())
for _ in range(__):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(1, n):
		if a[i] != 0:
			g = min(d, a[i] * i)
			a[0] += g // i
			d -= g
	print(a[0])


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	(n, d) = map(int, stdin.readline().split())
	total = 0
	for (i, a) in enumerate(list(map(int, stdin.readline().split()))):
		c = a * i
		if c > d:
			total += d // i
			break
		total += a
		d -= c
	stdout.write('{}\n'.format(total))


import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

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

def F():
	return float(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	ans = []
	for _ in range(n):
		(a, b) = LI()
		l = LI()
		for i in range(a):
			if i == 0:
				continue
			if l[i] > 0:
				x = l[i] * i
				if x > b:
					c = b // i
					l[0] += c
					break
				else:
					b -= x
					l[0] += l[i]
		ans.append(l[0])
	for x in ans:
		print(x)
main()


t = int(input())
(line1s, line2s) = ([], [])
for i in range(t):
	line1s.append(input())
	line2s.append(input())

def solve(line1, line2):
	(n, d) = map(int, line1.split())
	a = list(map(int, line2.split()))
	ans = a[0]
	for i in range(1, n):
		for j in range(a[i]):
			if i <= d:
				ans += 1
				d -= i
	print(ans)
for i in range(t):
	solve(line1s[i], line2s[i])


def I():
	return list(map(int, input().split()))
for __ in range(int(input())):
	(n, d) = I()
	a = I()
	s = a[0]
	l = 1
	for i in range(1, n):
		l = i
		d -= i * a[i]
		if d <= 0:
			break
		s += a[i]
	if d <= 0:
		d += l * a[l]
		s += d // l
	print(s)


a = int(input())
for p in range(a):
	(num_stacks, days) = map(int, input().split())
	spis_stacks = list(map(int, input().split()))
	count = 0
	for i in range(1, len(spis_stacks)):
		if spis_stacks[i] == 0:
			continue
		elif spis_stacks[i] * i > days:
			count += days // i
			break
		else:
			count += spis_stacks[i]
			days -= spis_stacks[i] * i
	print(count + spis_stacks[0])


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	f = a[0]
	step = 0
	for i in range(1, len(a)):
		step += 1
		dif = d - a[i] * step
		if dif >= 0:
			a[0] += a[i]
			a[i] -= a[i]
			d = dif
		else:
			temp = d // step
			a[i] -= temp
			d -= temp
			a[0] += temp
			print(a[0])
			break
	else:
		print(a[0])


T = int(input())
for _ in range(0, T):
	(n, d) = map(int, input().split())
	s = [int(x) for x in input().split()]
	ans = s[0]
	for i in range(1, len(s)):
		if i * s[i] <= d:
			ans += s[i]
			d -= i * s[i]
		else:
			ans += d // i
			break
	print(ans)


def solve():
	case = int(input())
	for _t in range(case):
		(n, m) = map(int, input().split())
		li = list(map(int, input().split()))
		ans = li[0]
		for i in range(1, n):
			if li[i] * i > m:
				ans += int(m / i)
				break
			else:
				ans += li[i]
				m -= li[i] * i
		print(ans)
solve()


t = int(input())
while t:
	(n, x) = map(int, input().split())
	l = list(map(int, input().split()))
	(s, c) = (0, 0)
	for i in range(1, len(l)):
		if l[i] == 0:
			continue
		elif x != 0:
			while l[i]:
				l[i] = l[i] - 1
				x = x - i
				if x == 0:
					c += 1
					break
				elif x < 0:
					break
				c += 1
		else:
			break
	print(c + l[0])
	t = t - 1


def solve():
	(n, k) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	price = 1
	while k >= price and price < len(arr):
		if arr[price] == 0:
			price += 1
			continue
		arr[price] -= 1
		k -= price
		arr[0] += 1
	print(arr[0])
t = int(input())
while t:
	solve()
	t -= 1


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	summ = 0
	for j in range(d):
		if summ == d or len(a) <= 1:
			break
		else:
			for k in range(1, len(a)):
				if a[k] > 0:
					if summ + k > d:
						break
					else:
						summ = summ + k
						a[k] = a[k] - 1
						a[0] += 1
						break
	print(a[0])


t = int(input())
while t > 0:
	(n, d) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	while d > 0:
		for j in range(1, n):
			if a[j] > 0:
				a[j] -= 1
				a[j - 1] += 1
				break
		d -= 1
	print(a[0])
	t -= 1


def solve(n, d, a):
	i = 1
	for i in range(1, n):
		if a[i] * i <= d:
			a[0] += a[i]
			d -= a[i] * i
			a[i] = 0
		else:
			a[0] += int(d / i)
			break
	print(a[0])
nt = input()
for _ in range(int(nt)):
	(n, d) = [int(x) for x in input().split()]
	a = []
	a = [int(x) for x in input().split()]
	solve(n, d, a)


t = int(input())
for _ in range(t):
	(n, d) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	for i in range(1, n):
		mn = min(d // i, a[i])
		a[0] += mn
		if d == mn:
			break
		d -= mn * i
	print(a[0])


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = list(map(int, input().split()))
	if n == 1:
		print(*arr)
	else:
		for i in range(1, n):
			while m > 0 and arr[i] > 0:
				m -= i
				if m >= 0:
					arr[0] += 1
					arr[i] -= 1
		print(arr[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().strip().split())
	s = list(map(int, input().strip().split()))
	d1 = 0
	for i in range(1, n):
		d1 = d
		d = d - s[i] * i
		if d <= 0:
			s[0] += d1 // i
			break
		else:
			s[0] += s[i]
	print(s[0])


for test in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = a[0]
	for i in range(1, n):
		x = k // i
		if a[i] <= x:
			s += a[i]
			k -= i * a[i]
		else:
			s += x
			break
	print(s)


def go():
	(n, d) = map(int, input().split())
	vals = list(map(int, input().split()))
	res = vals[0]
	for i in range(1, n):
		mx = d // i
		cnt = min(mx, vals[i])
		res += cnt
		d -= i * cnt
	print(res)
t = int(input())
for _ in range(t):
	go()


for q in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	for x in range(1, a):
		c = min(l[x], b // x)
		l[0] += c
		b -= c * x
		if b <= x:
			break
	print(l[0])


x = int(input())
for i in range(x):
	new_pile = []
	y = input().split(' ')
	days = int(y[1])
	piles = input().split(' ')
	for j in range(len(piles)):
		new_pile.append(int(piles[j]))
	total = new_pile[0]
	for k in range(1, len(new_pile)):
		if days > 0:
			custo = new_pile[k] * k
			if custo <= days:
				total += new_pile[k]
				days -= custo
			else:
				total += days // k
				days -= days // k * k
		else:
			break
	print(total)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	for i in range(1, n):
		if d == 0:
			break
		if a[i] == 0:
			continue
		if a[i] * i <= d:
			a[0] += a[i]
			d -= a[i] * i
		else:
			for j in range(a[i] - 1, 0, -1):
				if j * i <= d:
					a[0] += j
					d -= j * i
					break
	print(a[0])


from math import ceil, sqrt, gcd

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

def si():
	return input()

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

def li():
	return list(mi())
t = ii()
while t:
	t -= 1
	(n, d) = mi()
	a = li()
	if n > 1:
		a[0] += min(d, a[1])
		d -= a[1]
		if d > 0:
			k = 2
			for i in range(2, n):
				a[0] += min(d // k, a[i])
				d -= k * a[i]
				k += 1
				if d <= 0:
					break
		print(a[0])
	else:
		print(a[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(d):
		if n == 1 or d == 0:
			print(a[0])
			break
		elif n == 0:
			print(0)
			break
		for j in range(1, n):
			if a[j] > 0:
				a[j] = a[j] - 1
				a[j - 1] = a[j - 1] + 1
				break
		if i == d - 1:
			print(a[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	hay = list(map(int, input().split()))
	cnt = hay[0]
	for i in range(1, n):
		while hay[i] > 0 and d - i >= 0:
			d -= i
			hay[i] -= 1
			cnt += 1
	print(cnt)


t = int(input())
while t != 0:
	(n, d) = map(int, input().split())
	a = [int(x) for x in input().split()]
	for i in range(1, len(a)):
		tmp = min(d // i, a[i])
		d -= tmp * i
		a[0] += tmp
	print(a[0])
	t -= 1


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	haybales = tuple(map(int, input().split()))
	ans = haybales[0]
	for i in range(1, n):
		if d > 0:
			x = min(haybales[i], d // i)
			ans += x
			d -= x * i
		else:
			break
	print(ans)


t = int(input())
for tt in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = a[0]
	r = 1
	while d // r > 0 and r < n:
		if a[r] > 0:
			if a[r] >= d // r:
				ans += d // r
				d = 0
			else:
				ans += a[r]
				d -= a[r] * r
				r += 1
		else:
			r += 1
	print(ans)


def solve(n, m, arr):
	ans = arr[0]
	for i in range(1, n):
		if i * arr[i] <= m:
			ans += arr[i]
			m -= i * arr[i]
		else:
			ans += m // i
			break
	print(ans)

def main():
	inp = lambda : [int(x) for x in input().split()]
	tc = int(input())
	for _ in range(tc):
		(n, m) = inp()
		arr = inp()
		solve(n, m, arr)
main()


for i in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for j in range(1, n):
		move = min(a[j], d // j)
		a[0] += move
		d -= move * j
	print(a[0])


from sys import stdin, stdout
for i in range(0, int(input())):
	(m, n) = map(int, input().split())
	l = [int(x) for x in stdin.readline().split()]
	s = 0
	for i in range(1, m):
		a = min(l[i], n // i)
		n -= a * i
		s += a
	print(s + l[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	i = 1
	if n > 1:
		while d and i < n:
			ch = min(l[i], d // i)
			d -= ch * i
			c += ch
			if ch < l[i]:
				break
			i += 1
	c += l[0]
	print(c)


n = int(input())
for j in range(n):
	l1 = list(map(int, list(input().split())))
	d = l1[1]
	w = list(map(int, list(input().split())))
	t = 0
	for i in range(1, len(w)):
		if t + i > d:
			break
		while w[i] != 0 and t < d:
			w[i] = w[i] - 1
			w[0] += 1
			t += i
			if t + i > d:
				break
	print(w[0])


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	Query.append((N, K, A))
for (N, K, A) in Query:
	ans = 0
	for (i, a) in enumerate(A):
		cost = i * a
		if cost <= K:
			ans += a
			K -= cost
		else:
			ans += K // i
			break
	print(ans)


def f(n, d, a):
	d_ = d
	i = 0
	s = a[i]
	for j in range(n - 1):
		value = 0
		if i + j + 1 < n:
			value += a[i + j + 1]
		k = min(d_ // (j + 1), value)
		if d_ // (j + 1) == 0:
			break
		s += k
		d_ -= (j + 1) * k
	print(s)
t = int(input())
for i in range(t):
	(n, d) = (int(i) for i in input().split(' '))
	a = [int(i) for i in input().split(' ')]
	f(n, d, a)


def ProcessInputs():
	(N, D) = map(int, input().strip().split())
	L = list(map(int, input().strip().split()))
	S = L[0]
	for i in range(1, len(L)):
		if L[i]:
			if i <= D:
				Q = int(D / i)
				if Q <= L[i]:
					D = D - Q * i
					S += Q
				else:
					Q = L[i]
					D = D - Q * i
					S += Q
	print(S)
	return
T = int(input())
for _ in range(T):
	ProcessInputs()


import sys
import math
import itertools
import functools
import collections
import operator

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

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

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

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

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
arr = []
t = ii()
for _ in range(t):
	(n, d) = mi()
	a = li()
	ans = a[0]
	i = 1
	for i in range(1, n):
		ans += min(a[i], d // i)
		d -= min(a[i], d // i) * i
		if d < i:
			break
	arr.append(ans)
print(*arr, sep='\n')


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	(n, m) = list(map(int, sys.stdin.readline().rstrip().split()))
	num = list(map(int, sys.stdin.readline().rstrip().split()))
	re = num[0]
	for i in range(1, len(num)):
		if int(m / i) <= num[i]:
			re += int(m / i)
			break
		re += num[i]
		m -= num[i] * i
	print(re)


import math
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	mm = 0
	i = 1
	j = 1
	for i in range(1, len(l)):
		if l[i] == 0:
			continue
		if l[i] * i <= k:
			mm += l[i]
			k -= l[i] * i
		else:
			mm += math.floor(k / i)
			break
	print(l[0] + mm)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	pos = 1
	while d and pos < n:
		if arr[pos] == 0:
			pos += 1
			continue
		if d - pos < 0:
			break
		arr[pos] -= 1
		arr[0] += 1
		d -= pos
	print(arr[0])


T = int(input())
for i in range(T):
	inp = list(map(int, input().split(' ')))
	n = inp[0]
	m = inp[1]
	arr = list(map(int, input().split(' ')))
	for j in range(1, n):
		if j * arr[j] <= m:
			arr[0] += arr[j]
			m -= j * arr[j]
		else:
			for k in range(arr[j] + 1):
				if j * k > m:
					arr[0] += k - 1
					m -= j * (k - 1)
					break
			break
	print(arr[0])


for i in range(int(input())):
	(n, d) = map(int, input().split())
	lst = [int(i) for i in input().split()]
	a = 1
	for j in lst[1:]:
		if j == 0:
			a += 1
			continue
		elif d - j * a >= 0:
			lst[0] += j
			d -= j * a
			a += 1
		else:
			while d < j * a:
				j -= 1
			lst[0] += j
			break
	print(lst[0])


test_cases = int(input())
for t in range(test_cases):
	(n, d) = [int(i) for i in input().split()]
	hayStacks = [int(i) for i in input().split()]
	total = hayStacks[0]
	for j in range(1, n):
		hays = hayStacks[j]
		if d < 0:
			break
		toAdd = min(hays, d // j)
		d -= toAdd * j
		total += toAdd
	print(str(total))


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	if len(arr) == 1:
		print(arr[0])
	else:
		for pos in range(1, len(arr)):
			while arr[pos] > 0 and d >= pos:
				arr[pos] -= 1
				arr[0] += 1
				d -= pos
		print(arr[0])


for ct in range(int(input())):
	(n, d) = map(int, input().split())
	v = [int(i) for i in input().split()]
	res = v[0]
	for i in range(1, n):
		res += min(v[i], d // i)
		d = max(0, d - v[i] * i)
		if d == 0:
			break
	print(res)


for i in range(int(input())):
	(n, d) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	for j in range(1, len(a)):
		if a[j] > 0:
			for k in range(1, a[j] + 1):
				if d >= j:
					d = d - j
					a[0] += 1
	print(a[0])


I = input
R = lambda : map(int, input().split())
for _ in range(int(I())):
	(n, d) = R()
	a = list(R())
	ans = 0
	for i in range(1, n):
		temp = min(a[i], d // i)
		a[0] += temp
		d -= temp * i
	print(a[0])


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	p1 = arr[0]
	i = 1
	while d > 0 and i < len(arr):
		if d > arr[i] * i:
			d -= arr[i] * i
			p1 += arr[i]
		else:
			p1 += d // i
			d = 0
		i += 1
	print(p1)


from sys import stdin, stdout
t = int(stdin.readline())
for case in range(t):
	(n, d) = map(int, stdin.readline().split())
	ary = list(map(int, stdin.readline().split()))
	ans = ary[0]
	for i in range(1, n):
		if ary[i] > 0 and d > 0:
			for j in range(ary[i], 0, -1):
				if i * j <= d:
					ans += j
					d -= i * j
					break
	stdout.write('{}\n'.format(ans))


from bisect import *
from math import *
t = int(input())
for i in range(t):
	(n, d) = input().split()
	n = int(n)
	d = int(d)
	arr = list(map(int, input().split()))
	arr1 = []
	ini = 0
	for j in range(1, n):
		for k in range(arr[j]):
			arr1.append(j + ini)
			ini = arr1[-1]
	x = bisect_left(arr1, d)
	if x == len(arr1):
		print(sum(arr))
	elif arr1[x] == d:
		print(x + 1 + arr[0])
	else:
		print(x + arr[0])


t = int(input())
for x in range(t):
	(n, d) = map(int, input().split())
	hay = list(map(int, input().split()))
	for f in range(1, n):
		while hay[f] > 0 and d >= f:
			hay[f] -= 1
			hay[0] += 1
			d -= f
	print(hay[0])


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict

def solution(n, d, arr):
	while d:
		for i in range(1, n):
			if arr[i]:
				arr[i - 1] += 1
				arr[i] -= 1
				break
		d -= 1
	write(arr[0])

def main():
	for _ in range(r_int()):
		(n, d) = r_array()
		arr = r_array()
		solution(n, d, arr)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

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

def r_int():
	return int(input())

def p_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


t = int(input())
for _ in range(t):
	ans = 0
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	ans += a[0]
	i = 1
	while d > 0:
		if not i <= d:
			break
		if i >= n:
			break
		if a[i] > 0:
			ans += 1
			a[i] -= 1
			d -= i
		if a[i] == 0:
			i += 1
	print(ans)


for i in range(0, int(input())):
	(n, d) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	l = len(a)
	c = a[0]
	o = 0
	for j in range(1, l):
		for u in range(0, a[j]):
			if d - j >= 0:
				c += 1
			else:
				o = 1
				break
			d -= j
		if o == 1:
			break
	print(c)


import os
import operator
import sys
from _collections import defaultdict
import bisect
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		arr = inar()
		for i in range(1, n):
			while arr[i] > 0:
				if i <= k:
					arr[0] += 1
					arr[i] -= 1
					k -= i
				else:
					break
			if i > k:
				break
		print(arr[0])
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()


t = int(input())
lm = []
for i in range(t):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	days = d
	for i in range(1, n):
		while arr[i] > 0 and days >= i:
			arr[i] = arr[i] - 1
			days -= i
			arr[0] += 1
	lm.append(arr[0])
if n == 0:
	print(0)
else:
	for i in range(t):
		print(lm[i])


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	list_ = list(map(int, input().split()))
	for i in range(1, x):
		if y > 0:
			j = 1
			while i * j <= y and list_[i] > 0:
				list_[0] += 1
				list_[i] -= 1
				y -= i
		else:
			break
	print(list_[0])


def main():
	nTest = int(input())
	for i in range(nTest):
		(n, d) = map(int, input().split())
		pilas = list(map(int, input().split()))
		maximo = pilas[0]
		pos = 1
		while d > 0 and pos < n:
			if pilas[pos] > 0:
				pasos = min(int(d / pos), pilas[pos])
				maximo = maximo + pasos
				d = d - pasos * pos
			pos = pos + 1
		print(maximo)
main()


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	for e in range(1, len(l)):
		l[e] = e * l[e]
	ans = 0
	for r in range(1, len(l)):
		d = d - l[r]
		if d <= 0:
			d = d + l[r]
			ans = ans + d // r
			break
		else:
			ans = ans + l[r] // r
	print(ans + l[0])


import math
k = int(input())
alfabet = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10, 'k': 11, 'l': 12, 'm': 13, 'n': 14, 'o': 15, 'p': 16, 'q': 17, 'r': 18, 's': 19, 't': 20, 'u': 21, 'v': 22, 'w': 23, 'x': 24, 'y': 25, 'z': 26}
while k > 0:
	lista_1 = list(map(int, input().split()))
	lista_2 = list(map(int, input().split()))
	n = lista_1[0]
	d = lista_1[1]
	zile = d
	total = lista_2[0]
	for i in range(1, n):
		if zile <= d:
			punere = min(lista_2[i], int(math.floor(zile / i)))
			zile -= punere * i
			total += punere
	print(total)
	k = k - 1


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	l = [*map(int, input().split())]
	ans = l[0]
	for i in range(1, n):
		while l[i] > 0:
			l[i] -= 1
			if d - i >= 0:
				l[0] += 1
				d -= i
			else:
				break
	print(l[0])


for _ in range(int(input())):
	(n, d) = [int(i) for i in input().split()]
	lst = [int(i) for i in input().split()]
	sum = lst[0]
	i = 1
	while d != 0 and i < n:
		if d > lst[i] * i:
			sum = sum + lst[i]
			d = d - lst[i] * i
		else:
			sum = sum + d // i
			break
		i += 1
	print(sum)


t = int(input())
ans = []
sum = 0
j = 0
for i in range(t):
	(n, d) = map(int, input().strip().split())
	a = list(map(int, input().strip().split()))
	j = 1
	while d > 0 and len(a) > 1:
		if a[j] == 0:
			if j == len(a):
				break
			while j != len(a) and a[j] == 0:
				j = j + 1
			if j == len(a):
				break
			a[j - 1] += 1
			a[j] = a[j] - 1
			d = d - 1
			j = j - 1
		else:
			a[j] = a[j] - 1
			a[j - 1] += 1
			d = d - 1
			if j != 1:
				j = j - 1
	ans.append(a[0])
for i in ans:
	print(i)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = input().split()
	ans = 0
	for (i, num) in enumerate(a):
		if i == 0:
			ans = int(num)
		else:
			num = int(num)
			cnt = min(d // i, num)
			d -= cnt * i
			ans += cnt
	print(ans)


t = int(input())
for i in range(t):
	nd = [int(c) for c in input().split()]
	a = [int(c) for c in input().split()]
	kq = a[0]
	j = 1
	while nd[1] > 0 and j < nd[0]:
		if nd[1] >= a[j] * j:
			nd[1] = nd[1] - a[j] * j
			kq += a[j]
			j += 1
		else:
			kq = kq + nd[1] // j
			nd[1] = 0
	print(kq)


s = int(input())
res = []
for i in range(s):
	(n, d) = map(int, input().split())
	ls = list(map(int, input().split()))
	if n == 1:
		rs = ls[0]
	else:
		for (index, value) in enumerate(ls[1:]):
			if d >= (index + 1) * value:
				ls[0] += ls[index + 1]
				d -= (index + 1) * value
			else:
				ls[0] = ls[0] + d // (index + 1)
				break
		rs = ls[0]
	res.append(rs)
for i in res:
	print(i)


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	count = a[0]
	for x in range(n - 1):
		if (x + 1) * a[x + 1] <= d:
			d -= (x + 1) * a[x + 1]
			count += a[x + 1]
		else:
			b = d // (x + 1)
			d -= d // (x + 1)
			count += b
			break
	print(count)


t = int(input())
for i in range(t):
	temp = [int(x) for x in input().split()]
	n = temp[0]
	d = temp[1]
	a = [int(x) for x in input().split()]
	result = 0
	for i in range(1, n):
		if d // i >= a[i]:
			result += a[i]
			d -= a[i] * i
		else:
			result += d // i
			break
	print(a[0] + result)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	ai = list(map(int, input().split()))
	for j in range(d):
		for i in range(1, n):
			if ai[i] > 0:
				ai[i] -= 1
				ai[i - 1] += 1
				break
	print(ai[0])


n = int(input())
for k in range(n):
	(l, d) = map(int, input().strip().split())
	v = list(map(int, input().strip().split()))
	out = v[0]
	c = 1
	while d >= c:
		if c >= l:
			break
		if v[c] * c >= d:
			out += int(d / c)
			d = 0
		else:
			out += v[c]
			d -= v[c] * c
		c += 1
	print(out)


testnumber = int(input().split()[0])
for i in range(testnumber):
	(n, d) = [int(v) for v in input().split()]
	piles = [int(p) for p in input().split()]
	target = piles[0]
	piles[0] = 'test'
	for day in range(d):
		p = 0
		if len(piles) > 1:
			if piles[1] > 0:
				p = 1
			else:
				for pile in piles[1:]:
					if pile > 0:
						p = piles.index(pile)
						break
		if p > 1:
			piles[p - 1] += 1
			piles[p] -= 1
		elif p == 1:
			piles[p] -= 1
			target += 1
	print(target)


t = int(input())
for q in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = a[0]
	for j in range(1, n):
		ans += min(d // j, a[j])
		d -= min(d // j, a[j]) * j
	print(ans)


t = int(input())
for _ in range(t):
	(n, d) = [int(i) for i in input().strip().split()]
	piles = [int(i) for i in input().strip().split()]
	sm = piles[0]
	for i in range(1, n):
		if int(d / i) == 0:
			break
		tmp = min(int(d / i), piles[i])
		d -= i * tmp
		sm += tmp
	print(sm)


t = int(input())
count = 0
ans = []
while count < t:
	r = input()
	(n, d) = r.split()
	a = input()
	a = [int(x) for x in a.split()]
	if int(n) == 1:
		ans.append(a[0])
	else:
		cur = 2
		while cur <= int(n) and int(d) // (cur - 1) > 0:
			dn = a[cur - 1] * (cur - 1)
			if dn <= int(d):
				a[0] += a[cur - 1]
				d = int(d) - dn
			else:
				a[0] += int(d) // (cur - 1)
				d = int(d) - int(d) // (cur - 1) * (cur - 1)
			cur += 1
		ans.append(a[0])
	count += 1
for y in ans:
	print(y)


def foo():
	(n, d) = list(map(int, input().split()))
	piles = list(map(int, input().split()))
	ptr = 1
	mult = 1
	while ptr < len(piles):
		if piles[ptr] * mult < d:
			piles[0] += piles[ptr]
			d -= piles[ptr] * mult
		else:
			piles[0] += d // mult
			break
		ptr += 1
		mult += 1
	print(int(piles[0]))
t = int(input())
for i in range(t):
	foo()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	t = 1
	res = l[0]
	while t < n:
		if l[t] > 0:
			l[t] -= 1
			l[0] += 1
			k -= t
		if l[t] == 0:
			t += 1
		res = l[0]
		if k == 0:
			res = l[0]
			break
		if k < 0:
			res = l[0] - 1
			break
	print(res)


t = int(input())
for i in range(t):
	(n, d) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	cnt = a[0]
	for i in range(1, len(a)):
		if a[i] != 0:
			if a[i] * i <= d:
				cnt += a[i]
				d -= a[i] * i
			else:
				x = d // i
				cnt += x
				d -= x * i
	print(cnt)


t = int(input())
for i in range(t):
	(n, days) = map(int, input().split())
	A = [int(j) for j in input().split()]
	res = A[0]
	if n != 1:
		fl = True
		steps = 1
		while fl:
			a0 = A[steps]
			if a0 != 0:
				power = days // steps
				if power > a0:
					res += a0
					days -= a0 * steps
				else:
					res += power
					fl = False
			steps += 1
			if days == 0 or days < steps:
				fl = False
			if steps >= n:
				fl = False
	print(res)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	if a == 1:
		print(l[0])
	else:
		r = l[0]
		for j in range(1, a):
			p = j * l[j]
			if p < b:
				r += l[j]
				b -= p
			else:
				r += b // j
				break
		print(r)


for _ in range(int(input())):
	(haybales, days) = map(int, input().split())
	piles = list(map(int, input().split()))
	for i in range(1, haybales):
		if days != 0:
			haybales_moved = min(piles[i], days // i)
			piles[0] += haybales_moved
			days -= haybales_moved * i
		else:
			break
	print(piles[0])


def f(l, d):
	n = len(l)
	s = l[0]
	for i in range(1, len(l)):
		if d > i * l[i]:
			s += l[i]
			d -= i * l[i]
		else:
			return s + d // i
	return s
t = int(input())
while t > 0:
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	print(f(l, d))
	t -= 1


nc = int(input())
for cas in range(nc):
	(n, d) = map(int, input().split())
	l = [int(i) for i in input().split()]
	for i in range(1, n):
		if i * l[i] <= d:
			d -= i * l[i]
			l[0] += l[i]
		else:
			l[0] += d // i
			d %= i
	print(l[0])


t = int(input())
for i in range(t):
	(n, d) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	counter = a[0]
	i = 1
	while d > 0 and i < n:
		qqq = a[i] * i
		if qqq > d:
			qqq = d // i
			counter += qqq
			d = 0
		else:
			d = d - qqq
			counter += a[i]
		i = i + 1
	print(counter)


def main():
	(n, d) = map(int, input().split())
	aa = list(map(int, input().split()))
	for (dist, val) in enumerate(aa[1:]):
		dist += 1
		if d < dist:
			break
		mn = min(val, d // dist)
		aa[0] += mn
		d -= mn * dist
	print(aa[0])
t = int(input())
for _ in range(t):
	main()


def solve():
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	(i, ans) = (1, a[0])
	while d > 0 and i < n:
		k = d // i
		d -= i * min(a[i], k)
		ans += min(a[i], k)
		i += 1
	print(ans)
t = int(input())
for _ in range(t):
	solve()


import math
n = int(input())
for t in range(n):
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = [b[i] * i for i in range(1, len(b))]
	aux = a[1]
	for y in range(len(c)):
		if c[y] <= aux:
			b[0] += c[y] / (y + 1)
			aux -= c[y]
		elif c[y] != 0:
			b[0] += math.floor(aux / (y + 1))
			aux = 0
		if aux == 0:
			break
	print(int(b[0]))


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split(' '))
	heap = input().split(' ')
	for j in range(len(heap)):
		heap[j] = int(heap[j])
	count = heap[0]
	a = 1
	while d > 0 and len(heap) > 1:
		if heap[a] > 0:
			if d >= a:
				d -= a
				count += 1
				heap[a] -= 1
			else:
				d = 0
		elif heap[a] <= 0 and a == len(heap) - 1:
			break
		else:
			a += 1
	print(count)


t = int(input())
while t != 0:
	(n, d) = map(int, input().split())
	arrN = list(map(int, input().split()))
	result = arrN[0]
	if n == 1:
		result = arrN[0]
	else:
		i = 1
		j = 1
		for i in range(1, n, 1):
			while d > 0 and arrN[i] > 0:
				d -= i
				arrN[i] -= 1
				if d >= 0:
					result += 1
	print(result)
	t -= 1


for _ in range(int(input())):
	(m, n) = input().split()
	m = int(m)
	n = int(n)
	x = [int(x) for x in input().split()]
	for i in range(1, len(x)):
		if x[i] > int(n / i):
			x[0] += int(n / i)
			n = n - int(n / i)
			break
		else:
			x[0] += x[i]
			n = n - x[i] * i
	print(x[0])


t = int(input())
while t > 0:
	(n, d) = [int(ele) for ele in input().split()]
	a = [int(ele) for ele in input().split()]
	res = a[0]
	for i in range(1, n):
		while a[i] > 0 and d >= i:
			res += 1
			a[i] -= 1
			d -= i
	print(res)
	t -= 1


def candh(l, d):
	if len(l) == 1:
		return l[0]
	elif d < l[1]:
		return d + l[0]
	else:
		i = 1
		count = l[0]
		while d - i >= 0 and i < len(l):
			if i * l[i] < d:
				count += l[i]
				d = d - i * l[i]
				i += 1
			else:
				for j in range(1, l[i] + 1):
					if d - i >= 0:
						d = d - i
						count += 1
					else:
						return count
				i += 1
		return count
for _ in range(int(input())):
	(l, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(candh(arr, d))


q = int(input())
for z in range(0, q):
	n = list(map(int, input().split()))
	a = list(map(int, input().split()))
	j = 0
	p = 0
	l = 0
	for i in range(1, n[0]):
		l += i * a[i]
		if l > n[1]:
			j = 1
			break
		p += a[i]
	if j == 1:
		l = l - i * a[i]
		for w in range(1, a[i] + 1):
			if i * w > n[1] - l:
				break
	p = p + a[0]
	if j == 1:
		p = p + w - 1
	print(p)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		(n, d) = [int(x) for x in input().split()]
		(*a,) = [int(x) for x in input().split()]
		res = a[0]
		tempd = d
		for i in range(n - 1):
			reqd = a[i + 1] * (i + 1)
			if tempd > reqd:
				tempd -= reqd
				res += a[i + 1]
			else:
				rreqd = tempd // (i + 1)
				res += rreqd
				break
		yield res
t = int(input())
ans = gift()
print(*ans, sep='\n')


def cow_haybales(arr, n, d):
	if n == 1:
		return arr[0]
	j = 1
	while d != 0:
		k = arr[j]
		while k != 0 and d != 0:
			if d - j >= 0:
				arr[0] += 1
				k -= 1
				d -= j
			else:
				break
		if d - j <= 0 or d == 0 or j == n - 1:
			break
		if k == 0:
			j += 1
	return arr[0]
t = int(input())
for _ in range(t):
	nd = input().split()
	n = int(nd[0])
	d = int(nd[1])
	arr = list(map(int, input().split()))
	print(cow_haybales(arr, n, d))


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	if len(a) == 1:
		print(a[0])
	else:
		j = 1
		while d > 0 and j < len(a):
			dd = a[j] * j
			if dd > d:
				k = d // j
				a[0] += k
				break
			else:
				d = d - dd
				a[0] = a[0] + a[j]
				j = j + 1
		print(a[0])


import math
for i in range(int(input())):
	(a, b) = list(map(int, input().split()))
	first = list(map(int, input().split()))
	counter = 0
	for j in range(1, len(first)):
		for _ in range(first[j]):
			for k in range(j, 0, -1):
				if b > 0 and first[k] != 0:
					first[k - 1] += 1
					first[k] -= 1
					b -= 1
	print(first[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	li = list(map(int, input().split()))
	for h in range(d):
		for j in range(1, len(li)):
			if li[j] > 0:
				li[j - 1] = li[j - 1] + 1
				li[j] = li[j] - 1
				break
	print(li[0])


t = int(input())
for _ in range(t):
	arr1 = list(map(int, input().strip().split()))
	arr2 = list(map(int, input().strip().split()))
	(n, d) = (arr1[0], arr1[1])
	res = arr2[0]
	i = 1
	while i < n:
		if arr2[i] == 0:
			i += 1
			continue
		if d >= i:
			res += 1
			arr2[i] -= 1
			d -= i
		else:
			break
	print(res)


from sys import stdin, stdout
import bisect
import math

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

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

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

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

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

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	(n, k) = mp()
	l = li()
	for i in range(k):
		for j in range(1, n):
			if l[j] > 0:
				l[j] -= 1
				l[j - 1] += 1
				break
	print(l[0])
for _ in range(inp()):
	solve()


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

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

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

def solve():
	(n, d) = rl()
	A = rl()
	answer = A[0]
	for i in range(1, n):
		if A[i] * i <= d:
			answer += A[i]
			d -= A[i] * i
		else:
			answer += d // i
			break
	print(answer)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


t = int(input())
for tt in range(t):
	(n, d) = (int(i) for i in input().split())
	arr = [int(i) for i in input().split()]
	cnt = 0
	for i in range(1, n):
		num = min(arr[i], d // i)
		d -= i * num
		cnt += num
	print(arr[0] + cnt)


from math import factorial
from collections import Counter
from heapq import heapify, heappop, heappush
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 comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')

def main():
	N = int(input())
	for _ in range(N):
		(n, d) = RL()
		arr = list(RL())
		res = arr[0]
		for i in range(1, n):
			if d <= 0:
				break
			else:
				res += min(arr[i] * i, d) // i
				d -= min(arr[i] * i, d) // i * i
		print(res)
main()


x = int(input())
for i in range(x):
	(l, t) = map(int, input().split())
	(s, j, p) = (input().split(), 0, 0)
	d = int(s[0])
	while j < l - 1:
		j = j + 1
		if t >= j * int(s[j]):
			(t, d) = (t - j * int(s[j]), d + int(s[j]))
		else:
			(t, d) = (t % j, d + t // j)
			p = 1
			break
	print(d)


for i in range(int(input())):
	(n, d) = map(int, input().split())
	a = [int(s) for s in input().split()]
	for j in range(d):
		for k in range(1, n):
			if a[k] != 0:
				a[k - 1] += 1
				a[k] -= 1
				break
		else:
			break
	print(a[0])


import sys
import bisect
from collections import deque

def no():
	print('NO')

def dist(z, c):
	return (z[0] - c[0]) * (z[0] - c[0]) + (z[1] - c[1]) * (z[1] - c[1])

def vec(z, c):
	return z[0] * c[1] - z[1] * c[0]

def pro(z, c):
	return [z[0] - c[0], z[1] - c[1]]

def main():
	(n, d) = [int(i) for i in sys.stdin.readline().split()]
	q = [int(i) for i in sys.stdin.readline().split()]
	res = 0
	for i in range(1, n):
		if d < i:
			break
		elif q[i] * i <= d:
			d -= q[i] * i
			res += q[i]
		else:
			res += d // i
			break
	print(res + q[0])
for i in range(int(sys.stdin.readline())):
	main()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	c = 0
	for i in range(1, n):
		l[0] += min(m // i, l[i])
		m = m - min(m, l[i] * i)
	print(l[0])


T = int(input())
for t in range(T):
	(n, d) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	for i in range(1, n):
		move = min(A[i], d // i)
		A[0] += move
		d -= move * i
	print(A[0])


import sys
input = sys.stdin.readline
for _ in range(int(input().strip())):
	(n, k) = list(map(int, input().strip().split()))
	arr = list(map(int, input().strip().split()))
	ans = arr[0]
	for i in range(1, n):
		if arr[i] * i <= k:
			ans += arr[i]
			k -= arr[i] * i
		else:
			ans += k // i
			break
		if k <= 0:
			break
	print(ans)


import sys
t = int(input())
g = sys.stdin.readlines()
y = 0
for i in range(t):
	(n, d) = map(int, g[y].split())
	y += 1
	a = list(map(int, g[y].split()))
	y += 1
	answer = a[0]
	j = 1
	while d > 0 and j < n:
		if j * a[j] <= d:
			answer += a[j]
			d -= j * a[j]
		else:
			answer += d // j
			d = 0
		j += 1
	print(answer)


t = int(input())
vec = []
for i in range(t):
	(n, d) = [int(j) for j in input().split(' ')]
	a = [int(j) for j in input().split(' ')]
	stog = a[0]
	for j in range(1, n):
		if d > a[j] * j:
			stog += a[j]
			d += -a[j] * j
		else:
			stog += d // j
			break
	vec.append(str(stog))
print(' '.join(vec))


t = int(input())
for _ in range(t):
	(n, days) = list(map(int, input().split(' ')))
	haybales = list(map(int, input().split(' ')))
	i = 1
	while days > 0 and i < len(haybales):
		while haybales[i] > 0:
			if days < i:
				break
			else:
				haybales[0] += 1
				haybales[i] -= 1
				days -= i
		i += 1
	print(haybales[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split(' '))
	y = list(map(int, input().split()))
	i = 1
	k = 1
	while i < n and d > 0:
		if y[i] * k > d:
			y[0] += d // k
			d = d - 2
			break
		else:
			y[0] += y[i]
			d = d - k * y[i]
		i += 1
		k += 1
	print(y[0])


t = int(input())
for i in range(t):
	(n, t) = list(map(int, input().split()))
	num = list(map(int, input().split()))
	res = 0
	for j in range(n):
		while t >= j and num[j] > 0:
			num[j] -= 1
			t -= j
			res += 1
	print(res)


import math
import operator

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

def nCr(n, r):
	return math.factorial(n) / (math.factorial(r) * math.factorial(n - r))

def isKthBitSet(n, k):
	if n & 1 << k - 1:
		return True
	else:
		return False

def maximalRectangle(matrix):
	if not matrix or not matrix[0]:
		return 0
	n = len(matrix[0])
	height = [0] * (n + 1)
	ans = 0
	for row in matrix:
		for i in range(n):
			height[i] = height[i] + 1 if row[i] == '0' else 0
		stack = [-1]
		for i in range(n + 1):
			while height[i] < height[stack[-1]]:
				h = height[stack.pop()]
				w = i - 1 - stack[-1]
				ans = max(ans, h * w)
			stack.append(i)
	return ans

def matched(str):
	count = 0
	for i in str:
		if i == '(':
			count += 1
		elif i == ')':
			count -= 1
		if count < 0:
			return False
	return count == 0

def isValid(h, m, nh, nm):
	l = [0, 1, 5, -1, -1, 2, -1, -1, 8, -1]
	if l[h // 10] == -1 or l[h % 10] == -1 or l[m // 10] == -1 or (l[m % 10] == -1):
		return False
	resh = l[m % 10] * 10 + l[m // 10]
	resm = l[h % 10] * 10 + l[h // 10]
	return resh < nh and resm < nm

def solve():
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	while d > 0:
		d -= 1
		for i in range(1, n):
			if l[i] > 0:
				l[i] -= 1
				l[i - 1] += 1
				break
	print(l[0])
t = int(input())
while t > 0:
	t -= 1
	solve()


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	f = list(map(int, input().split()))
	for j in range(1, len(f)):
		if d == 0:
			break
		if f[j] != 0 and d >= f[j] * j:
			d -= f[j] * j
			f[0] += f[j]
		elif f[j] != 0 and d < f[j] * j:
			f[0] += d // j
			d = 0
	print(f[0])


for i in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	now = 0
	i = 1
	while now < d and i < n:
		if a[i] == 0:
			i += 1
		else:
			a[i] -= 1
			now += i
			if now <= d:
				a[0] += 1
	print(a[0])


T = int(input())
for _ in range(T):
	(N, D) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	days_left = D
	for (i, a) in enumerate(A):
		if i == 0:
			continue
		take_i = min(days_left // i, a)
		A[0] += take_i
		days_left -= take_i * i
	print(A[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	pile1 = arr[0]
	i = 1
	while d != 0 and i < n:
		if arr[i] == 0:
			i += 1
			continue
		if arr[i] * i <= d:
			d = d - arr[i] * i
			arr[0] += arr[i]
			i += 1
		else:
			arr[0] = arr[0] + d // i
			break
	print(arr[0])


from sys import stdin, stdout
from os import path
if path.exists('inp.txt'):
	stdin = open('inp.txt', 'r')
q = int(stdin.readline())
for _ in range(q):
	(n, m) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	ans = a[0]
	i = 1
	while m > 0 and i < n:
		if m < i:
			break
		x = min(int(m / i), a[i])
		ans += x
		m -= x * i
		i += 1
	print(ans)


t = int(input())
for _ in range(t):
	(n, d) = (int(i) for i in input().split())
	a = [int(i) for i in input().split()]
	i = 0
	count = 0
	while d > 0 and i < n:
		if d < i:
			break
		if a[i] > 0:
			a[i] -= 1
			d -= i
			count += 1
		else:
			i += 1
	print(count)


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	i = 0
	while b >= 0 and i < a - 1:
		i += 1
		b -= l[i] * i
		l[0] += l[i]
	if b < 0:
		print(l[0] - math.ceil(abs(b) / i))
	else:
		print(l[0])


a = int(input())
for i in range(a):
	(n, d) = map(int, input().split())
	z = list(map(int, input().split()))
	if n == 1:
		print(z[0])
	elif z[1] >= d:
		print(z[0] + d)
	else:
		for i in range(1, len(z)):
			if d <= 0:
				break
			if d > i * z[i] or z[i] == 0:
				d = d - i * z[i]
				z[0] = z[0] + z[i]
			else:
				while d >= 0:
					d = d - i
					if d >= 0:
						z[0] = z[0] + 1
					else:
						break
		print(z[0])


def maxOfCol1(a, k):
	(res, i) = (a[0], 1)
	while k > 0 and i < len(a):
		if i * a[i] < k:
			k -= i * a[i]
			res += a[i]
		else:
			res += k // i
			k = 0
		i += 1
	return res
t = int(input())
for i in range(t):
	(n, d) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	print(maxOfCol1(a, d))


import sys

def main():
	for _ in range(int(sys.stdin.readline())):
		(n, d) = map(int, sys.stdin.readline().split())
		l = [int(y) for y in sys.stdin.readline().split()]
		ans = l[0]
		flag = 0
		for i in range(1, n):
			x = l[i] * i
			if x > d:
				flag = 1
				break
			else:
				ans += l[i]
				d = d - x
		if flag == 1:
			for j in range(l[i]):
				d = d - i
				if d >= 0:
					ans += 1
				else:
					break
		print(ans)
main()


import sys
for _mind_control in range(int(input())):
	(n, d) = [int(i) for i in sys.stdin.readline().split()]
	arr = [int(i) for i in sys.stdin.readline().split()]
	answer = 0
	for i in range(1, n):
		if d < i:
			break
		elif arr[i] * i <= d:
			d -= arr[i] * i
			answer += arr[i]
		else:
			answer += d // i
			break
	print(answer + arr[0])


from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
			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:
			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')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))

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

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

def zzz():
	return [int(i) for i in fast().split()]
(z, zz) = (fast, lambda : map(int, z().split()))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer, end='\n'):
	stdout.write(str(answer) + end)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
num = int(z())
for _ in range(num):
	(n, m) = zzz()
	arr = zzz()
	while m > 0:
		c = 1
		for i in range(1, n):
			if arr[i] > 0 and m > 0:
				c = 0
				m -= 1
				arr[i] -= 1
				arr[i - 1] += 1
				break
		if c:
			break
	print(arr[0])


import math
for _ in range(int(input())):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	days_left = d
	ans = 0
	cost = [0]
	for i in range(1, n):
		cost.append(i * arr[i])
	for i in range(1, n):
		if cost[i] <= days_left:
			ans += arr[i]
			days_left -= cost[i]
		else:
			ans += days_left // i
			break
	print(ans + arr[0])


from sys import exit

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

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

def liis():
	return list(map(int, input().split()))
t = ii()
for _ in range(t):
	(n, d) = iis()
	a = liis()
	ans = a[0]
	for i in range(1, len(a)):
		for j in range(a[i]):
			d -= i
			if d < 0:
				break
			ans += 1
		if d < 0:
			break
	print(ans)


t = int(input())
l = []
for i in range(t):
	que = [int(j) for j in input().strip().split()]
	n = que[0]
	d = que[1]
	lst = [int(j) for j in input().strip().split()]
	Sum = lst[0]
	for i in range(1, len(lst)):
		if lst[i]:
			MAX = int(d / i)
			if MAX >= lst[i]:
				d = d - lst[i] * i
				Sum = Sum + lst[i]
			else:
				d = d - MAX * i
				Sum = Sum + MAX
				break
	l.append(Sum)
for i in l:
	print(i)


import sys
import math
from collections import defaultdict
from sys import stdin
input = stdin.readline
m = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 5)
T = int(input())
for _ in range(T):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	ans = arr[0]
	for i in range(1, n):
		if arr[i] * i <= d:
			ans += arr[i]
			d -= arr[i] * i
		else:
			x = arr[i] * d // (arr[i] * i)
			ans += x
			d = 0
			break
	print(ans)


from sys import stdin, stdout
t = 1

def lint():
	return list(map(int, input().split()))
t = int(input())
for i in range(t):
	(n, d) = lint()
	l = lint()
	ans = l[0]
	for i in range(1, n):
		while l[i] > 0 and d >= i:
			ans += 1
			d -= i
			l[i] -= 1
	print(ans)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, D) = [int(x) for x in input().split()]
		A = [int(x) for x in input().split()]
		ans = A[0]
		for (i, a) in enumerate(A[1:]):
			if D <= 0:
				break
			x = min(a * (i + 1), D)
			ans += min(a, D // (i + 1))
			D -= x
		print(ans)
main()


t = int(input())
for case_num in range(t):
	(n, d) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	for i in range(1, n):
		can_move = min(d // i, a[i])
		d -= can_move * i
		a[0] += can_move
		if d <= 0:
			break
	print(a[0])


tcase = int(input())
for t in range(tcase):
	aa = [int(item) for item in input().split()]
	n = aa[0]
	d = aa[1]
	a = [int(item) for item in input().split()]
	cost = 0
	ans = a[0]
	for i in range(1, n):
		while a[i] > 0:
			cost = i
			a[i] -= 1
			if cost <= d:
				d -= cost
				ans += 1
	print(ans)


for _ in range(int(input())):
	(n, x) = map(int, input().split())
	a = list(map(int, input().split()))
	j = 1
	i = 0
	while j < n and x > 0:
		p = j - i
		y = x // p
		a[i] += min(y, a[j])
		x -= p * min(y, a[j])
		j += 1
	print(a[i])


testCases = int(input())
ret = []
for cases in range(testCases):
	(piles, days) = map(int, input().split(' '))
	hay = list(map(int, input().split(' ')))
	if piles == 1:
		ret.append(hay[0])
	else:
		for i in range(days):
			for j in range(1, len(hay)):
				if hay[j] != 0:
					hay[j - 1] = hay[j - 1] + 1
					hay[j] = hay[j] - 1
					break
		ret.append(hay[0])
for i in ret:
	print(i)


cases = int(input().strip())
for case in range(cases):
	(n, d) = list(map(int, input().strip().split(' ')))
	a = list(map(int, input().strip().split(' ')))
	done = False
	for i in range(1, n):
		while a[i] > 0:
			if d >= i:
				d -= i
				a[0] += 1
				a[i] -= 1
			else:
				done = True
				break
		if done:
			break
	print(a[0])


from sys import stdin, stdout
t = int(stdin.readline().strip())
for caso in range(t):
	(n, m) = map(int, stdin.readline().strip().split())
	s = list(map(int, stdin.readline().strip().split()))
	for i in range(m):
		for j in range(1, n):
			if s[j] > 0:
				s[j - 1] += 1
				s[j] -= 1
				break
	stdout.write('%d\n' % s[0])


def max_haybales(arr, days):
	result = arr[0]
	for (i, item) in enumerate(arr[1:]):
		temp = item * (i + 1)
		if temp <= days:
			result += item
			days -= temp
		else:
			result += days // (i + 1)
			days = 0
		if days <= 0:
			break
	return result
for _ in range(int(input().strip())):
	(n, d) = list(map(int, input().strip().split()))
	arr = list(map(int, input().strip().split()))
	print(max_haybales(arr, d))


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

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

def mi():
	return map(int, input().split())
for _ in range(ii()):
	(n, d) = mi()
	piles = ai()
	ans = piles[0]
	for i in range(1, n):
		balls = piles[i]
		if balls > 0:
			trans = d // i
			if trans <= balls:
				ans += trans
				break
			else:
				ans += balls
				d -= balls * i
	print(ans)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	ntest = int(stdin.readline())
	for test in range(ntest):
		(n, d) = [int(x) for x in stdin.readline().split()]
		a = [int(x) for x in stdin.readline().split()]
		for (i, x) in enumerate(a):
			if i == 0:
				continue
			k = min(x, d // i)
			a[0] += k
			d -= k * i
		stdout.write('%d\n' % a[0])
	return 0
main()


from sys import stdin, stdout
for i in range(int(stdin.readline())):
	(num_haybales, num_days) = map(int, stdin.readline().split())
	haybales = list(map(int, stdin.readline().split()))
	for i in range(num_days):
		for j in range(1, num_haybales):
			if haybales[j] != 0:
				haybales[j] -= 1
				haybales[j - 1] += 1
				break
	print(haybales[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	i = 1
	while d > 0 and i < len(a):
		if a[i] > 0:
			val = 0
			for x in range(1, a[i] + 1):
				if x * i <= d:
					val = x * i
			d -= val
			a[0] += val // i
		i += 1
	print(a[0])


def get_maximum(haybales, n, d):
	count = 0
	for i in range(1, n):
		haybale = haybales[i]
		duration = i * haybale
		if d - duration < 0:
			haybale = d // i
			duration = haybale * i
			d -= duration
			count += haybale
			return count
		count += haybale
		d -= duration
	return count
t = int(input())
for _ in range(t):
	(n, d) = tuple(map(int, input('').strip().split(' ')))
	haybales = list(map(int, input('').strip().split(' ')))
	print(haybales[0] + get_maximum(haybales, n, d))


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


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	d = 0
	ind = 1
	while d != k and ind < n:
		if a[ind] == 0:
			ind += 1
		else:
			a[ind] -= 1
			a[ind - 1] += 1
			if ind != 1:
				ind -= 1
			d += 1
	print(a[0])


import sys
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		(n, d) = map(int, input().split())
		arr = list(map(int, input().split()))
		result = arr[0]
		for idx in range(1, len(arr)):
			if idx == 0:
				continue
			if d >= arr[idx] * idx:
				result += arr[idx]
				d -= arr[idx] * idx
				continue
			result += d // idx
			break
		print(result)
main()


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = a[0]
	i = 1
	if n == 1:
		print(a[0])
	else:
		while d > 0 and i < n:
			if a[i] > 0:
				p = d // i if d // i < a[i] else a[i]
				ans += p
				d -= i * p
				i += 1
			else:
				i += 1
		print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	mass = [int(x) for x in input().split()]
	answer = 0
	for j in range(n):
		x = j * mass[j]
		if x <= m:
			m -= x
			answer += mass[j]
		else:
			answer += m // j
			break
	print(answer)


import math
testCases = int(input())
for _ in range(testCases):
	(n, d) = [int(x) for x in input().split()]
	piles = [int(x) for x in input().split()]
	for index in range(1, len(piles)):
		daysTake = index * piles[index]
		if d - daysTake >= 0:
			d -= daysTake
			piles[0] += piles[index]
			if d == 0:
				break
		else:
			piles[0] += d // index
			break
	print(piles[0])


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
t = ini()
for _ in range(t):
	(n, d) = inm()
	a = inl()
	ans = a[0]
	for i in range(1, n):
		x = min(d // i, a[i])
		ans += x
		d -= x * i
		if d == 0:
			break
	print(ans)


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = a[0]
	i = 1
	while i < n and a[i] * i <= d:
		ans += a[i]
		d -= a[i] * i
		i += 1
	if i < n:
		ans += d // i
	print(ans)


def main():
	for _ in range(int(input())):
		(n, d) = map(int, input().split())
		a = list(map(int, input().split()))
		ans = a[0]
		for i in range(1, n):
			if a[i] * i <= d:
				d -= a[i] * i
				ans += a[i]
			else:
				ans += d // i
				break
		print(ans)
main()


for _ in range(int(input())):
	(n, d) = [int(x) for x in input().split(' ')]
	arr = [int(x) for x in input().split(' ')]
	ans = arr[0]
	for i in range(1, len(arr)):
		md = d // i
		ans = ans + min(md, arr[i])
		d = d - min(md, arr[i]) * i
	print(ans)


def solv():
	(n, d) = map(int, input().split())
	arr = map(int, input().split())
	s = 0
	for (i, x) in enumerate(arr):
		sh = i * x
		if sh <= d:
			s += x
			d -= sh
		else:
			s += d // i
			break
	print(s)
for _ in range(int(input())):
	solv()


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	packs = list(map(int, input().split()))
	ans = packs[0]
	for i in range(1, n):
		ans += min(packs[i], d // i)
		if d <= packs[i] * i:
			break
		d -= packs[i] * i
	print(ans)


t = int(input())
while t != 0:
	(n, d) = map(int, input().split())
	a = [int(x) for x in input().split()]
	r = 0
	for i in range(1, n):
		cost = i * a[i]
		r += min(cost, d) // i
		d -= min(cost, d)
	print(a[0] + r)
	t -= 1


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	if len(a) == 1 or d == 0:
		print(a[0])
		continue
	cpos = 1
	while d >= cpos and cpos < len(a):
		if a[cpos] > 0 and d - cpos >= 0:
			a[0] += 1
			a[cpos] -= 1
			d -= cpos
		elif a[cpos] == 0:
			cpos += 1
	print(a[0])


from collections import defaultdict as dd
import math

def nn():
	return int(input())

def li():
	return list(input())

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

def lm():
	return list(map(int, input().split()))
q = nn()
for i in range(q):
	(n, d) = mi()
	bales = lm()
	count = 0
	place = 1
	goodbales = bales[0]
	while count <= d - place and place < n:
		doable = min(bales[place], (d - count) // place)
		goodbales += doable
		count += doable * place
		place += 1
	print(goodbales)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	s = 0
	chc = 0
	add = 0
	for i in range(1, len(l)):
		for j in range(l[i]):
			s += i
			add += 1
			if s == d:
				print(l[0] + add)
				chc = 1
				break
			if s > d:
				print(add - 1 + l[0])
				chc = 1
				break
		if chc == 1:
			break
	if chc == 0:
		print(sum(l))


def main():
	T = int(input())
	for i in range(T):
		(n, d) = input().split()
		pile_string = input()
		piles = []
		piles = pile_string.split()
		piles = [int(i) for i in piles]
		for k in range(int(d)):
			for l in range(1, int(n)):
				if piles[l] > 0:
					piles[l] -= 1
					piles[l - 1] += 1
					break
		print(piles[0])
main()


from sys import *
input = stdin.readline
listInput = lambda : list(map(int, input().strip().split()))
lineInput = lambda : map(int, input().strip().split())
sJoin = lambda a, sep: f'{sep}'.join(a)
arrJoin = lambda a, sep: f'{sep}'.join(map(str, a))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, int(math.sqrt(n) + 1), 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def main():
	for _ in range(int(input())):
		(n, d) = lineInput()
		arr = listInput()
		if len(arr) == 1:
			print(arr[0])
		else:
			for i in range(1, n):
				while arr[i] > 0:
					if d - i < 0:
						break
					arr[0] += 1
					arr[i] -= 1
					d -= i
			print(arr[0])
main()


for t in range(int(input())):
	(n, d) = map(int, input().split())
	Pile = list(map(int, input().split()))
	ans = Pile[0]
	for i in range(1, n):
		if d == 0:
			break
		workperpiece = i
		maxpossible = d // i
		willshift = min(Pile[i], maxpossible)
		d = d - i * willshift
		ans += willshift
	print(ans)


n = int(input())
for t in range(n):
	hy = []
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	s = input()
	hy = s.split(' ')
	for i in range(len(hy)):
		hy[i] = int(hy[i])
	a1 = 0
	for i in range(1, a):
		a1 = i * hy[i]
		if a1 > b:
			hy[0] += b // i
			break
		b = b - a1
		hy[0] += hy[i]
	print(hy[0])


def tst(n, d, l):
	for i in range(1, n):
		if d >= i * l[i]:
			d -= l[i] * i
			l[0] += l[i]
		else:
			l[0] += d // i
			break
	print(l[0])
	pass
s = int(input())
for i in range(s):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	tst(n, d, l)


for i in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	n = d
	for j in range(1, len(a)):
		if a[j] != 0:
			if n <= 0:
				break
			while a[j] != 0:
				if n <= 0 or n < j:
					break
				a[j] -= 1
				n -= j
				a[0] += 1
	print(a[0])


import math
for _ in range(int(input())):
	(n, d) = map(int, input().split())
	com = list(map(int, input().split()))
	score = 0
	for i in range(1, n):
		if com[i] == 0:
			continue
		elif d / i >= com[i]:
			score += com[i]
			d -= i * com[i]
		else:
			score += math.floor(d / i)
			break
	print(com[0] + score)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	f = 0
	for j in range(d):
		if f == d:
			break
		elif len(a) <= 1:
			break
		elif len(a) >= 2:
			for k in range(1, len(a)):
				if a[k] > 0:
					if f + k > d:
						break
					else:
						f = f + k
						a[k] = a[k] - 1
						a[0] += 1
						break
	print(a[0])


for t in range(int(input())):
	(n, d) = [int(i) for i in input().split()]
	l = [int(i) for i in input().split()]
	res = l[0]
	for i in range(1, n):
		if d:
			temp = min(l[i], d // i)
			res += temp
			d -= temp * i
		else:
			break
	print(res)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	s = map(int, input().split())
	s = list(s)
	res = 0
	dni = 0
	for j in range(1, len(s)):
		dni = dni + s[j] * j
		res += s[j]
		if dni > d:
			while dni > d:
				dni = dni - (s[j] - (s[j] - 1)) * j
				res -= 1
			break
	print(res + s[0])


def solve():
	a = input().split()
	b = input().split()
	for i in range(0, len(a)):
		a[i] = int(a[i])
	for i in range(0, len(b)):
		b[i] = int(b[i])
	kq = b[0]
	for i in range(1, len(b)):
		if a[1] - b[i] * i <= 0:
			kq += int(a[1] / i)
			break
		else:
			a[1] -= b[i] * i
			kq += b[i]
	print(kq, '\n')
t = int(input())
for a in range(0, t):
	solve()


num_t = int(input())
for _ in range(num_t):
	(_, d) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	for i in range(1, len(arr)):
		t = min(arr[i], d // i)
		arr[0] += t
		d -= t * i
	print(arr[0])


def f(L, day):
	for i in range(1, len(L)):
		r = min(L[i], day // i)
		day -= r * i
		L[0] += r
	return L[0]
for _ in range(int(input())):
	(n, d) = map(int, input().split())
	print(f(list(map(int, input().split())), d))


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	if len(l) == 1:
		print(l[0])
		continue
	z = l[0]
	x = 1
	u = 0
	o = 0
	for i in l:
		if u == 1:
			break
		if o == 0:
			o = 1
			continue
		for j in range(i):
			if x <= m:
				m -= x
				z += 1
			else:
				u = 1
				break
		x += 1
	print(z)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	m_ = l[0]
	w = 1
	i = 1
	while d > 0:
		if i < n:
			if l[i] > 0:
				if d >= l[i] * w:
					m_ = m_ + l[i]
					d = d - l[i] * w
					l[i] = 0
					i += 1
					w += 1
				else:
					q = d // w
					m_ = m_ + q
					d = 0
			else:
				i += 1
				w += 1
		else:
			break
	print(m_)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for x in range(1, n):
		c = min(a[x], d // x)
		a[0] += c
		d -= c * x
	print(a[0])


I = lambda : map(int, input().split())
for _ in range(int(input())):
	(_, d) = I()
	s = 0
	for (i, a) in enumerate(I()):
		x = min(a, d // i) if i else a
		s += x
		d -= i * x
	print(s)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	lis = list(map(int, input().split()))
	ans = lis[0]
	i = 1
	while d > 0 and i < n:
		k = min(d, lis[i] * i)
		d -= k
		ans += k // i
		i += 1
	print(ans)


for i in range(int(input())):
	l = list(map(int, input().split()))
	m = list(map(int, input().split()))
	d = l[1]
	j = 1
	count = 0
	final = 0
	while j < len(m):
		if m[j] != 0:
			for k in range(m[j]):
				if count + j <= d:
					m[0] += 1
					count += j
		j += 1
	print(m[0])


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	for j in range(d):
		if d == 0:
			break
		for r in range(1, n):
			if r > d:
				d = 0
				break
			if arr[r] != 0:
				arr[0] += 1
				arr[r] -= 1
				d -= r
				break
	print(arr[0])


t = int(input())

def do_cnt(n, d, a):
	cnt = 0
	remain_d = d
	for i in range(1, n):
		if remain_d >= a[i] * i:
			cnt += a[i]
			remain_d -= a[i] * i
		else:
			cnt += remain_d // i
			break
	return a[0] + cnt
inputs = []
for i in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	inputs.append((n, d, a))
for inp in inputs:
	print(do_cnt(*inp))


from sys import stdin
num = int(input())
for i in range(num):
	(length, days) = map(int, input().split())
	pile = [int(x) for x in stdin.readline().rstrip().split()]
	j = 1
	while days > 0 and j < length:
		if pile[j] != 0 and j < length and (j <= days):
			pile[0] += 1
			pile[j] -= 1
			days -= j
		else:
			j += 1
	print(pile[0])


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	(n, d) = [int(x) for x in input().split()]
	h = [int(x) for x in input().split()]
	flag = False
	for i in range(n):
		if flag:
			break
		for j in range(n):
			if i != j:
				needed = i + j
				if needed > d:
					flag = True
					break
				while h[j] > 0 and d >= needed:
					h[j] -= 1
					h[0] += 1
					d -= needed
	print(h[0])


T = int(input())
for _ in range(T):
	(N, D) = map(int, input().split())
	A = [int(a) for a in input().split()]
	ANS = 0
	for i in range(N):
		if A[i] * i < D:
			ANS += A[i]
			D -= A[i] * i
		else:
			ANS += D // i
			break
	print(ANS)


def solve(N, D, V):
	i = 1
	while i < N:
		while V[i] > 0 and D - i >= 0:
			V[0] = V[0] + 1
			V[i] = V[i] - 1
			D -= i
		i = i + 1
	return V[0]

def main():
	T = int(input())
	while T > 0:
		(N, D) = map(int, input().split())
		V = list(map(int, input().split()))
		print(solve(N, D, V))
		T = T - 1
	return
main()


from math import *
from collections import *
from operator import itemgetter
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
t = ii()
for _ in range(t):
	(n, t) = iia()
	a = iia()
	c = a[0]
	tu = 0
	for i in range(1, n):
		if tu + a[i] * i <= t:
			tu += a[i] * i
			c += a[i]
		else:
			r = t - tu
			c += r // i
			break
	print(c)


def main():
	n = int(input())
	for i in range(n):
		(n_haybale, days) = map(int, input().split(' '))
		haybale = list(map(int, input().split(' ')))
		sum_hay = 0
		for i in range(len(haybale)):
			if days > haybale[i] * i:
				days -= haybale[i] * i
				sum_hay += haybale[i]
			else:
				sum_hay += days // i
				break
		print(sum_hay)
main()


def solve(a, n, d):
	total = a[0]
	for i in range(1, n):
		if i > d:
			return total
		if a[i] > 0:
			if i * a[i] <= d:
				total += a[i]
				d -= i * a[i]
			else:
				p = d // i
				total += p
				d -= p * i
	return total
for _ in range(int(input())):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	print(solve(a, n, d))


def solution(n, d, piles):
	maxi = piles[0]
	for (idx, pile) in enumerate(piles):
		if idx == 0:
			continue
		while piles[idx] > 0 and d - idx >= 0:
			d -= idx
			piles[idx] -= 1
			maxi += 1
	return maxi
t = int(input())
while t > 0:
	t -= 1
	(n, d) = [int(x) for x in input().split()]
	piles = [int(x) for x in input().split()]
	print(solution(n, d, piles))


t = int(input())
lis = []

def isNotInt(n):
	try:
		int(n)
		return False
	except:
		return True
for i in range(t):
	nl = []
	s = ''
	(a, b) = input().split()
	c = str(input()) + ' '
	for j in c:
		if isNotInt(j):
			nl.append(int(s))
			s = ''
			continue
		else:
			s += j
	lis.append([int(a), int(b), nl])
for (n, d, l) in lis:
	for i in range(d):
		for j in range(1, n):
			if l[j] > 0:
				l[j] -= 1
				l[j - 1] += 1
				break
	print(l[0])


q = int(input())
for i in range(q):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for j in range(1, n):
		val = a[j] * j
		kol = d // j
		a[0] += min(a[j], kol)
		d -= min(a[j], kol) * j
	print(a[0])


t = int(input())
while t > 0:
	s1 = input().split()
	n = int(s1[0])
	d = int(s1[1])
	val = input().split()
	hy = int(val[0])
	le = len(val)
	for i in range(1, le):
		if int(val[i]) == 0:
			pass
		elif d < i:
			break
		else:
			de = d // i
			if de <= int(val[i]):
				hy += de
				d -= de * i
			else:
				hy += int(val[i])
				d -= int(val[i]) * i
	print(hy)
	t -= 1


import sys
input = sys.stdin.readline

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

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

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

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

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	for test in range(tests):
		[n, d] = inlt()
		hay = inlt()
		out = hay[0]
		i = 1
		while i < len(hay):
			dum = hay[i] * i
			if d > dum:
				out = out + hay[i]
				d = d - dum
				i = i + 1
			else:
				out = out + int(d / i)
				break
		print(out)
	return
main()


for tc in range(int(input())):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	a = l[0]
	v = d
	for i in range(1, n):
		if l[i] * i <= v:
			a += l[i]
			v -= l[i] * i
		elif v == 0:
			break
		else:
			a += v // i
			break
	print(a)


t = int(input())
f = []
s = []
for i in range(t):
	f.append(list(map(int, input().split())))
	s.append(list(map(int, input().split())))

def solve(inf, raw):
	for i in range(inf[1]):
		for j in range(1, len(raw)):
			if raw[j] > 0:
				raw[j - 1] += 1
				raw[j] -= 1
				break
	return raw[0]
for i in range(t):
	print(solve(f[i], s[i]))


import sys
input = sys.stdin.readline
t = int(input())
for test in range(t):
	(n, d) = map(int, input().split())
	A = list(map(int, input().split()))
	ANS = A[0]
	ind = 1
	while d > 0 and ind < n:
		if d > ind * A[ind]:
			d -= ind * A[ind]
			ANS += A[ind]
			ind += 1
		else:
			ANS += d // ind
			break
	print(ANS)


t = int(input())
while t:
	(n, d) = map(int, input().split())
	l = [int(x) for x in input().split()]
	for g in range(d):
		for i in range(1, n):
			if l[i] > 0:
				l[i] -= 1
				l[i - 1] += 1
				break
	print(l[0])
	t -= 1


n = int(input())
for i in range(n):
	(m, k) = map(int, input().split())
	bi = list(map(int, input().split()))
	d = k
	for j in range(1, m):
		while d >= j and bi[j] > 0:
			d = d - j
			bi[j] -= 1
			bi[0] += 1
	print(bi[0])


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(n, d) = [int(item) for item in input().split()]
	a = [int(item) for item in input().split()]
	ans = a[0]
	for (i, item) in enumerate(a[1:]):
		takes = min(d // (i + 1), item)
		ans += takes
		d -= (i + 1) * takes
	print(ans)


for k in range(int(input())):
	(a, b) = list(map(int, input().split()))
	t = list(map(int, input().split()))
	for i in range(1, a):
		u = 0
		for f in range(t[i]):
			if b > 0:
				b -= 1 * i
				if b >= 0:
					t[0] += 1
				else:
					u += 1
					break
		if u > 0:
			break
	print(t[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	arr = list(map(int, input().split()))
	pile = arr[0]
	count = 0
	for i in range(1, n):
		cur = d // i
		if d >= arr[i] * i:
			count += arr[i]
			d -= arr[i] * i
		else:
			count += cur
			break
	print(pile + count)


def max_haybales(pile, d, n):
	if n == 1:
		return pile[0]
	counter = pile[0]
	for i in range(1, n):
		if pile[i] > 0 and d >= i:
			while d >= i and pile[i] > 0:
				counter += 1
				pile[i] -= 1
				d -= i
		if d < 0:
			break
	return counter
t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	pile = list(map(int, input().split()))
	print(max_haybales(pile, d, n))


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(1, n):
		tp = a[i] * i
		if tp >= d:
			a[0] += int(d / i)
			d = 0
			break
		elif tp != 0 and tp < d:
			a[0] += a[i]
			d = d - tp
	print(a[0])


for i in range(int(input())):
	(n, d) = map(int, input().split())
	l = [int(i) for i in input().split()][:n]
	for j in range(1, len(l)):
		if l[j] * j <= d:
			l[0] += l[j]
			d = d - l[j] * j
		else:
			h = d // j
			l[0] += h
			break
	print(l[0])


n = int(input())
for i in range(n):
	c = 0
	number = input().split()
	number = list(map(int, number))
	ls = input().split()
	ls = list(map(int, ls))
	for j in range(1, number[0]):
		if ls[j] == 0:
			pass
		else:
			while ls[j] > 0 and c <= number[1] - j:
				ls[0] += 1
				ls[j] -= 1
				c += j
	print(ls[0])


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	lst = list(map(int, input().split()))
	while d:
		for i in range(1, n):
			if lst[i] > 0:
				lst[i] -= 1
				lst[i - 1] += 1
				break
		d -= 1
	print(lst[0])


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	cnt = 0
	if len(arr) == 1:
		print(arr[0])
		continue
	else:
		for (idx, i) in enumerate(arr[1:]):
			for j in range(i):
				k -= idx + 1
				if k < 0:
					break
				cnt += 1
	print(arr[0] + cnt)


t = int(input())

def findAns(i, d, n, piles):
	ans = piles[0]
	count = d
	for r in range(1, n):
		rc = 0
		if i + r < n:
			rc = piles[i + r]
		if count >= r:
			bayles = min(rc, count // r)
			change = r * bayles
			ans += min(rc, count // r)
			count -= change
		else:
			return ans
		if count == 0:
			return ans
	return ans
for j in range(0, t):
	(n, d) = list(map(int, input().split()))
	piles = list(map(int, input().split()))
	arrMax = piles.copy()
	print(findAns(0, d, n, piles))


n = int(input())
l1 = []
for i in range(n):
	l = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l2.append(l[1])
	l1.append(l2)
for li in l1:
	n = len(li) - 1
	d = li[-1]
	i = 1
	k = 0
	while i <= n - 1:
		while d - i >= 0 and k == 0:
			if li[i] != 0:
				li[0] = li[0] + 1
				li[i] = li[i] - 1
				d = d - i
			else:
				k = 1
		i = i + 1
		k = 0
	print(li[0])


for _ in range(int(input())):
	(n, d) = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	mov = 0
	for i in range(d):
		for i in range(len(ar) - 1):
			if i < len(ar) - 1:
				if ar[i + 1] > 0:
					ar[i] = ar[i] + 1
					ar[i + 1] = ar[i + 1] - 1
					mov = mov + 1
					break
	print(ar[0])


import math
t = int(input())
while t:
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	for i in range(1, len(l)):
		l[0] = l[0] + l[i]
		d = d - i * l[i]
		x = i
		if d < 0:
			break
	if d >= 0:
		print(l[0])
	else:
		d = d * -1
		print(l[0] - math.ceil(d / x))
	t -= 1


t = int(input())
for _ in range(t):
	(n, d) = map(int, input().split())
	lis = list(map(int, input().split()))
	erg = lis[0]
	for i in range(1, n):
		if d <= 0:
			break
		moves = min(d // i, lis[i])
		erg += moves
		d -= moves * i
	print(erg)


for _ in range(int(input())):
	X = list(map(int, input().split()))
	(Numbers, Co) = (list(map(int, input().split())), 1)
	for i in range(1, X[0]):
		Min = min(X[1] // Co, Numbers[i])
		(Numbers[0], X[1], Co) = (Numbers[0] + Min, X[1] - Min * Co, Co + 1)
	print(Numbers[0])


t = int(input())
for i in range(t):
	(n, d) = list(map(int, input().split()))
	piles = list(map(int, input().split()))
	sol = piles[0]
	piles.pop(0)
	k = 0
	while d > 0 and k < len(piles):
		count = piles[k]
		cost = k + 1
		possible = d // cost
		if possible == 0:
			break
		if possible > count:
			possible = count
		d -= possible * cost
		sol += possible
		k += 1
	print(sol)


tests = int(input())
for _ in range(tests):
	(n, d) = map(int, input().split())
	h = list(map(int, input().split()))
	i = 1
	flag1 = 0
	if n == 1:
		print(h[0])
	else:
		while d > 0 and i < n:
			while h[i] > 0:
				if i <= d:
					d -= i
					h[0] += 1
				else:
					flag1 = 1
					break
				h[i] -= 1
			i += 1
			if flag1:
				break
		print(h[0])


I = input
R = lambda : map(int, input().split())
for _ in range(int(I())):
	(n, m) = R()
	a = list(R())
	for i in range(m):
		for j in range(1, n):
			if a[j]:
				a[j] -= 1
				a[j - 1] += 1
				break
	print(a[0])


data = input()
t = int(data)
res = []
for i in range(t):
	data = input()
	data = data.split(' ')
	n = int(data[0])
	d = int(data[1])
	temp = input()
	temp = temp.split(' ')
	compt = int(temp[0])
	i = 2
	while d != 0:
		if len(temp) > i - 1:
			a = int(temp[i - 1])
			if a > 0:
				nb = int(d / (i - 1))
				maxB = min(nb, a)
				compt = compt + maxB
				d = d - maxB * (i - 1)
			i = i + 1
		else:
			break
	res.append(compt)
for i in range(len(res)):
	print(res[i])


import math
t = int(input())
for __ in range(t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	s = a[0]
	for i in range(1, n):
		if a[i] * i <= d:
			s += a[i]
			d -= a[i] * i
			a[i] = 0
		elif math.floor(d / i) >= a[i]:
			s += a[i]
			d -= a[i] * i
			a[i] = 0
		else:
			s += math.floor(d / i)
			d -= math.floor(d / i) * i
	print(s)


q = int(input())
while q:
	(n, d) = input().split()
	(n, d) = (int(n), int(d))
	l = [int(i) for i in input().split()]
	ans = l[0]
	it = 1
	while d >= it and it < n:
		cur = min(l[it], d // it)
		d -= cur * it
		it += 1
		ans += cur
	print(ans)
	q -= 1


import sys
import bisect
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter
from itertools import combinations as comb
mod = pow(10, 9) + 7
mod2 = 998244353

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

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

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

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
for _ in range(int(data())):
	(n, d) = sp()
	arr = l()
	answer = arr[0]
	for i in range(1, n):
		answer += min(arr[i], d // i)
		d -= min(arr[i] * i, i * (d // i))
		if d <= 0:
			break
	print(answer)


tt = int(input())
for t in range(tt):
	(n, d) = map(int, input().split())
	h = list(map(int, input().split()))
	cumh = h[0]
	inext = 1
	while d > 0 and inext < n and (inext <= d):
		if h[inext] > 0:
			cumh += 1
			h[inext] = h[inext] - 1
			d -= inext
		else:
			inext += 1
	print(cumh)


t = int(input())
for i in range(0, t):
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	max = a[0]
	for k in range(1, n):
		if d < k:
			break
		while d >= k and a[k] > 0:
			max = max + 1
			d = d - k
			a[k] = a[k] - 1
	print(max)


t = int(input())
while t > 0:
	(n, d) = [int(x) for x in input().split()]
	l = [int(x) for x in input().split()]
	if n == 1:
		print(l[0])
	else:
		ans = l[0]
		for i in range(1, n):
			l[i] = i * l[i]
		for i in range(1, n):
			if d - l[i] >= 0:
				d -= l[i]
				ans += l[i] // i
			else:
				ans += d // i
				break
		print(ans)
	t -= 1


import sys
from pprint import pprint
if not 'DEBUG' in globals():
	readline = sys.stdin.readline

def read(map_func):
	return map_func(readline().rstrip())

def reads(map_func):
	return list(map(map_func, readline().rstrip().split()))

def readn(map_func, n):
	return [map_func(readline().rstrip()) for _ in range(n)]

def readint():
	return read(int)

def readints():
	return reads(int)

def readcol(n):
	return readn(int, n)

def readmat(n):
	return [readints() for _ in range(n)]

def readmap(n):
	return readn(list, n)

def makemat(n, m, v):
	return [[v] * m for _ in range(n)]

def zeromat(n, m=None):
	return makemat(n, m if m else n, 0)

def listmat(n, m=None):
	return [[[] for _ in range(m if m else n)] for _ in range(n)]

def crosslist(y, x, n=None, m=None):
	return [(p, q) for (p, q) in [(y, x + 1), (y - 1, x), (y, x - 1), (y + 1, x)] if (n == None or 0 <= p < n) and (m == None or 0 <= q < m)]

def roundlist(y, x, n=None, m=None):
	return [(p, q) for (p, q) in [(y, x + 1), (y - 1, x + 1), (y - 1, x), (y - 1, x - 1), (y, x - 1), (y + 1, x - 1), (y + 1, x), (y + 1, x + 1)] if (n == None or 0 <= p < n) and (m == None or 0 <= q < m)]

def plog(obj):
	pprint(obj) if 'DEBUG' in globals() else None

def log(msg, label=None):
	print((label + ': ' if label else '') + str(msg)) if 'DEBUG' in globals() else None

def _logmat(mat, label=None):
	fmt = '{:' + str(max((max((len(str(s)) for s in m)) for m in mat))) + 'd}'
	f = lambda row: '[' + ' '.join((fmt.format(x) for x in row)) + ']'
	[log('[' + f(row), label) if i == 0 else log((' ' * (len(label) + 3) if label else ' ') + f(row) + ']', None) if i == len(mat) - 1 else log((' ' * (len(label) + 3) if label else ' ') + f(row), None) for (i, row) in enumerate(mat)]

def logmat(mat, label=None):
	_logmat(mat, label) if 'DEBUG' in globals() else None
for _ in range(readint()):
	(N, D) = readints()
	A = readints()
	for i in range(1, N):
		if D >= A[i] * i:
			D -= A[i] * i
			A[0] += A[i]
		else:
			A[0] += D // i
			break
	print(A[0])


for _ in range(int(input())):
	(n, d) = tuple(map(int, input().split()))
	piles = list(map(int, input().split()))
	ans = piles[0]
	for i in range(1, n):
		can = min(piles[i], d // (i - 0))
		ans += can
		d -= can * (i - 0)
	print(ans)


m = int(input())
l = []
for _ in range(m):
	(t, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(d):
		for j in range(t - 1):
			if a[j + 1] != 0:
				a[j] += 1
				a[j + 1] -= 1
				break
	l.append(a[0])
for i in l:
	print(i)


from math import *
zzz = int(input())
for zz in range(zzz):
	(n, d) = map(int, input().split())
	a = [int(i) for i in input().split()]
	i = 1
	while i < n and d > 0:
		while d >= i and a[i] > 0:
			a[0] += 1
			d -= i
			a[i] -= 1
		i += 1
	print(a[0])


t = int(input())
for _ in range(t):
	(N, D) = map(int, input().split())
	A = list(map(int, input().split()))
	height = A[0]
	for i in range(1, len(A)):
		if A[i] * i <= D:
			height += A[i]
			D -= A[i] * i
		else:
			height += D // i
			break
	print(height)


def f1():
	T = int(input())
	while T != 0:
		T = T - 1
		A = [int(i) for i in input().split(' ')]
		B = [int(i) for i in input().split(' ')]
		print(Solver(A, B))

def Solver(A, B):
	N = A[0]
	D = A[1]
	Ans = 0
	Adder = 0
	for i in range(0, len(B)):
		if D == 0:
			return Ans
		elif B[i] == 0:
			continue
		else:
			SetBack = i
			x = B[i]
			if D < i:
				return Ans
			while D >= i and x != 0:
				D = D - i
				Ans = Ans + 1
				x = x - 1
			if D == 0:
				return Ans
	return Ans
f1()


def solve():
	(n, d) = [int(s) for s in input().strip().split()]
	A = [int(s) for s in input().strip().split()]
	result = A[0]
	for i in range(1, n):
		a = min(d // i, A[i])
		result += a
		d -= a * i
		if d < i:
			break
	print(result)

def main():
	for _ in range(int(input().strip())):
		solve()
main()


kl = int(input())
for l in range(kl):
	(n, d) = [int(i) for i in input().split()]
	k = 0
	pr = 0
	for i in input().split():
		if pr:
			continue
		i = int(i)
		if k == 0:
			s = i
			k += 1
			continue
		if d < k * i:
			print(s + d // k)
			pr = 1
			continue
		else:
			s += i
			d -= k * i
			k += 1
	if pr == 0:
		print(s)


t = int(input())
while t > 0:
	nd = list(map(int, input().split()))
	a = list(map(int, input().split()))
	s = a[0]
	for k in range(1, nd[0]):
		x = int(nd[1] / k)
		if not x < a[k]:
			x = a[k]
		nd[1] -= x * k
		s += x
	print(s)
	t -= 1


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
for case in range(itg()):
	(n, d) = mpint()
	arr = list(mpint())
	for _ in range(d):
		for i in range(1, n):
			if arr[i] != 0:
				arr[i] -= 1
				arr[i - 1] += 1
				break
	print(arr[0])


s = int(input(''))
while s > 0:
	(n, d) = input('').split()
	n = int(n)
	d = int(d)
	l = list(map(int, input('').split()))
	count1 = l[0]
	for i in range(1, n):
		if d <= 0:
			break
		if d >= l[i] * i:
			count1 += l[i]
			d = d - l[i] * i
		else:
			p = d // i
			count1 = count1 + p
			d = d - p * i
	print(count1)
	s = s - 1


import math
t = int(input())
for _i in range(t):
	(n, m) = map(int, input().split())
	s = list(map(int, input().split()))
	ans = s[0]
	for j in range(1, len(s)):
		if m <= 0:
			break
		if s[j] != 0:
			while m > 0 and s[j] > 0 and (m >= j):
				m -= j
				s[j] -= 1
				ans += 1
	print(ans)


MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
for _ in range(ii()):
	(n, d) = f()
	l = il()
	ans = 0
	for i in range(1, n):
		if d >= i:
			ans += min(l[i], d // i)
			d -= min(l[i], d // i) * i
		else:
			break
	print(ans + l[0])


from sys import *
for _ in range(int(input())):
	(a, d) = map(int, input().split())
	(A, arr) = (list(map(int, stdin.readline().split())), [0 for i in range(a)])
	for i in range(len(A)):
		arr[i] = A[i]
	while d > 0:
		for i in range(1, a):
			if arr[i] > 0:
				arr[i] -= 1
				arr[i - 1] += 1
				break
		d -= 1
	stdout.write(str(arr[0]) + '\n')


R = lambda : map(int, input().split())
(t,) = R()
for _ in [0] * t:
	(n, d) = R()
	r = i = 0
	for x in R():
		if i * x > d:
			r += d // i
			break
		d -= i * x
		r += x
		i += 1
	print(r)


import sys
from math import gcd, ceil, floor, sqrt
import heapq
from collections import defaultdict

def solve():
	fastinp = lambda : sys.stdin.readline().split(' ')
	inp = lambda : input().split(' ')
	iinp = lambda : int(inp()[0])
	ml = lambda x, y=int: list(map(y, x))
	t = iinp()
	for _ in range(t):
		(n, d) = ml(inp())
		hay = ml(inp())
		res = 0
		for i in range(1, n):
			if d < 0:
				break
			diff = i
			can_be_moved = d // diff
			to_be_moved = min(can_be_moved, hay[i])
			days_consumed = to_be_moved * diff
			d -= days_consumed
			res += to_be_moved
		print(hay[0] + res)
solve()


def solve():
	(n, d) = map(int, input().split())
	a = list(map(int, input().split()))
	for i in range(n):
		if i == 0:
			ans = a[i]
			continue
		k = a[i]
		while k > 0 and d >= i:
			k -= 1
			d -= i
			ans += 1
	print(ans)
for _ in range(int(input())):
	solve()


import sys

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

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

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

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

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

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(N, D) = MAP()
	A = LIST()
	for d in range(D):
		for i in range(1, N):
			if A[i] > 0:
				A[i - 1] += 1
				A[i] -= 1
				break
	print(A[0])


n = int(input())
for _ in range(n):
	(kk, m) = map(int, input().split())
	nums = list(map(int, input().split()))
	for (i, j) in enumerate(nums):
		if i == 0:
			res = j
		elif m != 0:
			if m >= i * j:
				m -= i * j
				res += j
			else:
				res += m // i
				m = 0
	print(res)


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	ls = [int(x) for x in input().split()]
	for i in range(d):
		for j in range(1, n):
			if ls[j] != 0:
				ls[j - 1] += 1
				ls[j] -= 1
				break
	print(ls[0])


for _ in range(int(input())):
	(n, d) = map(int, input().split())
	l = list(map(int, input().split()))
	anz = l[0]
	for i in range(1, n):
		if l[i] * i <= d:
			anz += l[i]
			d -= l[i] * i
		else:
			anz += d // i
			break
	print(anz)


def check_zeros(array):
	n = 0
	for i in array:
		if i == 0:
			n += 1
	if n == len(array):
		return True
	else:
		return False

def get_ans():
	(no_of_haybales, no_of_days) = [int(i) for i in input().split()]
	array = [int(i) for i in input().split()]
	current_window = 0
	if no_of_haybales == 1:
		return array[0]
	else:
		while no_of_days != 0:
			while array[current_window + 1] == 0 and current_window != no_of_haybales - 2:
				current_window += 1
			if check_zeros(array[1:]):
				no_of_days -= 1
			else:
				array[current_window] = array[current_window] + 1
				array[current_window + 1] = array[current_window + 1] - 1
				no_of_days -= 1
				current_window = 0
		return array[0]
n = int(input(''))
arr = []
for i in range(n):
	arr.append(get_ans())
for i in arr:
	print(i)


t = int(input())
for i in range(t):
	(n, d) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	result = arr[0]
	for j in range(1, n):
		curr = min(arr[j], d // j)
		result += curr
		d -= curr * j
	print(result)


import sys
import math
input = sys.stdin.readline
d = {}
t = int(input())
while t > 0:
	t -= 1
	(n, d) = map(int, input().split())
	a = [int(x) for x in input().split()]
	for i in range(1, n):
		a[0] += min(d // i, a[i])
		d -= min(d // i, a[i]) * i
		if d == 0:
			break
	print(a[0])