Shohag has an integer sequence $a_1, a_2, \ldots, a_n$. He can perform the following operation any number of times (possibly, zero):

Select any positive integer $k$ (it can be different in different operations).

Choose any position in the sequence (possibly the beginning or end of the sequence, or in between any two elements) and insert $k$ into the sequence at this position.

This way, the sequence $a$ changes, and the next operation is performed on this changed sequence.

For example, if $a=[3,3,4]$ and he selects $k = 2$, then after the operation he can obtain one of the sequences $[\underline{2},3,3,4]$, $[3,\underline{2},3,4]$, $[3,3,\underline{2},4]$, or $[3,3,4,\underline{2}]$.

Shohag wants this sequence to satisfy the following condition: for each $1 \le i \le |a|$, $a_i \le i$. Here, $|a|$ denotes the size of $a$.

Help him to find the minimum number of operations that he has to perform to achieve this goal. We can show that under the constraints of the problem it's always possible to achieve this goal in a finite number of operations.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 200$)  — the number of test cases.

The first line of each test case contains a single integer $n$ ($1 \le n \le 100$) — the initial length of the sequence.

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


-----Output-----

For each test case, print a single integer  — the minimum number of operations needed to perform to achieve the goal mentioned in the statement.


-----Examples-----

Input
4
3
1 3 4
5
1 2 5 7 4
1
1
3
69 6969 696969
Output
1
3
0
696966


-----Note-----

In the first test case, we have to perform at least one operation, as $a_2=3>2$. We can perform the operation $[1, 3, 4] \rightarrow [1, \underline{2}, 3, 4]$ (the newly inserted element is underlined), now the condition is satisfied.

In the second test case, Shohag can perform the following operations:

$[1, 2, 5, 7, 4] \rightarrow [1, 2, \underline{3}, 5, 7, 4] \rightarrow [1, 2, 3, \underline{4}, 5, 7, 4] \rightarrow [1, 2, 3, 4, 5, \underline{3}, 7, 4]$.

In the third test case, the sequence already satisfies the condition.

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms


Solutions:
for i in range(int(input())):
	x = int(input())
	arr = list(map(int, input().split()))
	brr = []
	for i in range(x):
		if arr[i] > i + 1:
			m = arr[i] - (i + 1)
			brr.append(m)
	if brr:
		print(max(brr))
	if not brr:
		print(0)


for _ in range(int(input())):
	n = int(input())
	line = list(map(int, input().split()))
	lar = 0
	for i in range(n):
		if line[i] - i - 1 > lar:
			lar = line[i] - i - 1
	print(lar)


for i in range(int(input())):
	n = int(input())
	now = 0
	arr = list(map(int, input().split()))
	ind = n
	while ind > 0:
		ni = arr.index(max(arr[:ind]))
		now += max(max(arr[:ind]) - (ni + 1 + now), 0)
		ind = arr.index(max(arr[:ind]))
	print(now)


for g in range(int(input())):
	l = int(input())
	a = [int(x) for x in input().split()]
	if len(a) == 1:
		c = a[0] - 1
		print(c)
	else:
		nu = []
		for i in range(l):
			d = a[i] - a.index(a[i]) - 1
			nu.append(d)
		print(max(nu))


import sys
input = sys.stdin.readline

def iinput():
	return int(input())

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

def i0input():
	return int(input()) - 1

def linput():
	return list(input().split())

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

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

def li0input():
	return list(map(lambda x: int(x) - 1, input().split()))

def mi0input():
	return map(lambda x: int(x) - 1, input().split())
INF = 10 ** 20
MOD = 1000000007
t = iinput()
for _ in [0] * t:
	n = iinput()
	A = liinput()
	ans = 0
	for (i, a) in enumerate(A):
		ans = max(ans, a - i - 1)
	print(ans)


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


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	(k, ind) = (0, 0)
	for j in range(n):
		if A[j] > ind + 1:
			k += A[j] - ind - 1
			ind += A[j] - ind - 1
		ind += 1
	print(k)


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


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


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


from __future__ import division, print_function
import os
import sys
from fileinput import input
from io import BytesIO, IOBase
import math
inf = float('inf')
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():

	def solve():
		n = int(input())
		arr = list(map(int, input().split()))
		ans = 0
		for i in range(n):
			if arr[i] > i + 1 + ans:
				ans += arr[i] - 1 - i - ans
		return ans
	t = int(input())
	for i in range(t):
		print(solve())
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


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


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


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	for j in range(n):
		a[j] -= j + 1
	print(max(a + [0]))


import sys
input = sys.stdin.readline

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

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

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

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	n = inp()
	a = lis()
	sofar = 0
	moves = 0
	for i in range(n):
		diff = a[i] - (i + 1 + sofar)
		if diff > 0:
			moves += diff
			sofar += diff
	print(moves)


import sys
from collections import deque
import heapq
import bisect
import copy
MOD = 1000000007
NO = lambda : print('NO')
YES = lambda : print('YES')
_1 = lambda : print(-1)
ari = lambda : [int(_) for _ in input().split()]
cin = lambda : int(input())
cis = lambda : input()
show = lambda x: print(x)
fast = lambda : sys.stdin.readline()
test_case = 1
test_case = int(input())
sys.setrecursionlimit(10 ** 6)

def ans():
	n = cin()
	arr = ari()
	count = 0
	intail = 1
	for i in range(n):
		if arr[i] > intail:
			dist = abs(intail - arr[i])
			count += dist
			intail += dist + 1
		else:
			intail += 1
	print(count)
	return
for _ in range(test_case):
	ans()


import math
from collections import OrderedDict
from collections import Counter
from itertools import combinations

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


import math
t = int(input())

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	max_dif = 0
	for (i, v) in enumerate(arr):
		max_dif = max(max_dif, v - i - 1)
	print(max_dif)
for _ in range(t):
	solve()


for _ in range(int(input())):
	input()
	d = max(0, max([int(x) - i for (i, x) in enumerate(input().split(), 1)]))
	print(d)


t = int(input())
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input().strip().split()))
	ans = 0
	for i in range(n):
		x = list1[i] - (i + 1)
		if x > ans:
			ans = x
	print(ans)


for _ in range(int(input())):
	s = int(input())
	l = list(map(int, input().split()))
	(p, j, k) = (1, 0, 0)
	while j != s:
		if l[j] > p:
			p += l[j] - p - 1
			k = 1
		j += 1
		p += 1
	if k != 1 and p == s + 1:
		print(0)
	else:
		print(p - s)


from sys import stdin
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip()
YN = lambda x: print('YES') if x else print('NO')
ceil_div = lambda a, b: -(-a // b)
mod = 10 ** 9 + 7
for _ in range(rn()):
	n = rn()
	a = rl()
	b = [max(0, a[i] - i - 1) for i in range(n)]
	print(max(b))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	mini = 0
	ind = 1
	for i in a:
		if i <= ind:
			ind += 1
		else:
			mini += i - ind
			ind += i - ind + 1
	print(mini)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	m = 10000000000
	for i in range(1, n + 1):
		m = min(i - l[i - 1], m)
	print(abs(m))
	t -= 1


import math
from collections import OrderedDict
t = int(input())
while t > 0:
	n = int(input())
	inp = input()
	a = list(map(int, inp.split(' ')))
	maxi = a[0] - 0 - 1
	for i in range(0, n):
		s = a[i] - i - 1
		if s > maxi:
			maxi = s
	print(max(maxi, 0))
	t -= 1


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


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(n) for n in input().split()]
	count = 0
	for k in range(n):
		if 1 + k + count < a[k]:
			count += a[k] - (1 + k + count)
	print(count)


for _ in range(int(input())):
	n = int(input())
	res = []
	l = [int(x) for x in input().split()]
	for i in range(1, n + 1):
		ans = l[i - 1] - i
		res.append(ans)
	if len(res) != 0:
		print(max(res))
	else:
		print(0)


x = int(input())
li = []
for i in range(x):
	y = int(input())
	ans = 0
	li = list(map(int, input().split(' ')))
	for j in range(len(li)):
		if li[j] > j + ans + 1:
			ans += li[j] - (ans + j + 1)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	(*a,) = map(int, input().split())
	a = [0] + a
	cnt = 0
	added = 0
	for i in range(n + 1):
		if a[i] > i + added:
			cnt += a[i] - i - added
			added += a[i] - i - added
	print(cnt)


import sys, os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for t in range(int(input())):
	n = int(input())
	num = list(map(int, input().split()))
	mun = [0] * n
	for i in range(n):
		mun[i] = num[i] - i
	print(max(mun) - 1)


for _ in range(int(input())):
	n = int(input())
	a = [0] + list(map(int, input().split()))
	v = 0
	for i in range(1, n + 1):
		v = max(v, a[i] - i)
	print(v)


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


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	m = 0
	for i in range(len(arr)):
		if arr[i] - (i + 1) > m:
			m = arr[i] - (i + 1)
	print(m)


t = int(input())
while t:
	t -= 1
	n = int(input())
	lst = list(map(int, input().split()))
	tot = 0
	for i in range(n):
		tot = max(tot, lst[i] - i - 1)
	print(tot)


for i in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	maxim = 0
	for j in range(n):
		if arr[j] - j - 1 > maxim:
			maxim = arr[j] - j - 1
	print(maxim)


t = int(input())
l = 1
while l <= t:
	n = int(input())
	x = input().split()
	size = []
	for i in range(len(x)):
		x[i] = int(x[i])
		size.append(x[i] - i - 1)
	val = max(size)
	if val > 0:
		print(val)
	else:
		print(0)
	l = l + 1


import math
from itertools import combinations as cm

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

def isPrime(x):
	i = 2
	while i * i <= x:
		if x % i == 0:
			return False
		i += 1
	return True

def solve():
	n = inp()
	a = inl()
	j = 1
	ans = 0
	for i in range(n):
		if a[i] <= j:
			j += 1
			continue
		else:
			ans += a[i] - j
			j += a[i] - j + 1
	print(ans)

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

def inp():
	return int(input())
t = 1
t = inp()
while t:
	solve()
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	operations = 0
	for i in range(1, len(a) + 1):
		if not a[i - 1] <= i:
			operations += 0 if a[i - 1] - i - operations < 0 else a[i - 1] - i - operations
	print(operations)


t = int(input())
for slkdja in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	ma = 0
	for i in range(n):
		ma = max(ma, l[i] - i)
	print(ma - 1)


from __future__ import print_function
from math import *
from collections import deque
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
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')
mod = 10 ** 9 + 7

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

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

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

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	l = inlt()
	ans = 0
	c = 0
	for i in range(n):
		if l[i] > i + ans + 1:
			c += l[i] - (i + ans + 1)
			ans += l[i] - (i + ans + 1)
	print(c)


for T in range(int(input())):
	N = int(input())
	a = [int(p) for p in input().split()]
	ans = 0
	final_pos = 0
	for i in range(len(a)):
		if a[i] > final_pos + 1:
			padding_req = a[i] - final_pos - 1
			ans += padding_req
			final_pos += padding_req
		final_pos += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		x = l[i] - ans - i - 1
		ans = max(ans, ans + x)
	print(ans)


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


_ = int(input())
for __ in range(_):
	n = int(input())
	l = list(map(int, input().split()))
	w = 0
	for x in range(1, len(l) + 1):
		if l[x - 1] > x + w:
			w += l[x - 1] - (x + w)
	print(w)


import sys
from math import factorial, gcd
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify, nlargest, nsmallest
from itertools import groupby, accumulate
from copy import deepcopy
MOD = 10 ** 9 + 7
INF = float('inf')
input = sys.stdin.readline
rl = lambda : list(map(int, input().split()))
rs = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	A = rl()
	res = 0
	for (i, a) in enumerate(A):
		res = max(res, a - (i + 1))
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()[:n]))
	(s, c) = (0, l[0])
	if l[0] > 1:
		s = l[0] - 1
	m = l[0]
	i = 1
	while i < n:
		m = max(l[i], c + 1)
		if m > c + 1:
			s += m - (c + 1)
			c = m - 1
		i += 1
		c += 1
	print(s)


from sys import stdin, stdout
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))
for _ in range(nmbr()):
	n = nmbr()
	a = lst()
	v = 1
	ans = 0
	for i in range(n):
		if a[i] >= v:
			ans += a[i] - v
			v = a[i] + 1
		else:
			v += 1
	print(ans)


t = int(input().strip())

def minNumOfOperations(l, n):
	re = 0
	m = int(l[0]) - 1
	for i in range(1, len(l)):
		if int(l[i]) - (i + 1) > m:
			m = int(l[i]) - (i + 1)
	return max(0, m)
for _ in range(t):
	n = int(input().strip())
	l = input().split(' ')
	re = minNumOfOperations(l, n)
	print(re)


t = int(input())
for i in range(0, t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	maxi = []
	for j in range(0, n):
		maxi.append(arr[j] - (j + 1))
	print(max(maxi))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	curr = 1
	count = 0
	for i in range(n):
		if arr[i] > curr:
			count += arr[i] - curr
			curr = arr[i]
		curr += 1
	print(count)


from cmath import sqrt
import math
from collections import defaultdict, deque, Counter
from functools import reduce
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	a = deque(a)
	ad = 0
	for i in range(n):
		if a[i] > i + 1 + ad:
			ad = ad + a[i] - (i + 1 + ad)
	print(ad)


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


for z in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	b = [0] * n
	for _ in range(n):
		b[_] = s[_] - _ - 1
	print(max(b))


def era(s):
	n_op = 0
	for (i, n) in enumerate(s):
		n_op += max(0, s[i] - (i + 1) - n_op)
	return n_op
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(k) for k in input().split()]
	print(era(a))


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


c = int(input())
ans = []
for i in range(c):
	l = int(input())
	m = list(map(int, input().split()))
	min1 = 0
	for j in range(l):
		if m[j] > j + 1:
			min1 = max(min1, m[j] - j - 1)
	ans.append(min1)
print(*ans, sep='\n')


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		ans = max(ans, A[i] - i - 1)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	al = list(map(int, input().split()))
	ans = 0
	ind = 1
	for (i, a) in enumerate(al):
		if a <= ind:
			ind += 1
		else:
			d = a - ind
			ans += d
			ind = a + 1
	print(ans)


t = int(input())
for i in range(t):
	a = int(input())
	x = list(map(int, input().split()))
	y = 0
	j = 0
	c = 0
	k = 0
	while k < len(x):
		if j + 1 < x[c]:
			z = x[c] - (j + 1)
			y += z
			j = x[c]
		else:
			j += 1
		c += 1
		k += 1
	print(y)


t = int(input())
for i in range(t):
	n = int(input())
	lst = input().split()
	a = []
	dem = 0
	for i in range(n):
		a.append(int(lst[i]))
	for i in range(n):
		if a[i] > i + 1 + dem:
			dem = a[i] - i - 1
	print(dem)


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


def get_ans(a, n):
	operations = 0
	elements_before = 0
	for i in range(n):
		elements_before += max(0, a[i] - elements_before)
		elements_before += 1
	return elements_before - n - 1
anss = []
t = int(input())
for _ in range(t):
	_n = int(input())
	_a = list(map(int, input().split()))
	anss.append(get_ans(_a, _n))
for ans in anss:
	print(ans)


from __future__ import division, print_function
import math
import sys
import os
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

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

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

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	l = inlt()
	v = 0
	for i in range(n):
		v = max(v, l[i] - i)
	print(v - 1)


t = int(input())
s = ''
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = 0
	for i in range(len(a)):
		if a[i] > i + 1 and a[i] - i - 1 > k:
			k = a[i] - i - 1
	s += str(k) + '\n'
print(s[:-1])


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


import bisect
import heapq
import math
import collections
import sys
import copy
from functools import reduce
import decimal
from io import BytesIO, IOBase
import os
import itertools
import functools
from types import GeneratorType
decimal.getcontext().rounding = decimal.ROUND_HALF_UP
graphDict = collections.defaultdict
queue = collections.deque

def bootstrap(f, stack=[]):

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

class Graphs:

	def __init__(self):
		self.graph = graphDict(set)

	def add_edge(self, u, v):
		self.graph[u].add(v)
		self.graph[v].add(u)

	def dfs_utility(self, nodes, visited_nodes, colors, parity, level):
		global count
		if nodes == 1:
			colors[nodes] = -1
		elif len(self.graph[nodes]) == 1 and parity % 2 == 0:
			if q == 1:
				colors[nodes] = 1
			else:
				colors[nodes] = -1
				count += 1
		elif parity % 2 == 0:
			colors[nodes] = -1
		else:
			colors[nodes] = 1
		visited_nodes.add(nodes)
		for neighbour in self.graph[nodes]:
			new_level = level + 1
			if neighbour not in visited_nodes:
				self.dfs_utility(neighbour, visited_nodes, colors, level - 1, new_level)

	def dfs(self, node):
		Visited = set()
		color = collections.defaultdict()
		self.dfs_utility(node, Visited, color, 0, 0)
		return color

	def bfs(self, node, f_node):
		count = float('inf')
		visited = set()
		level = 0
		if node not in visited:
			queue.append([node, level])
			visited.add(node)
		flag = 0
		while queue:
			parent = queue.popleft()
			if parent[0] == f_node:
				flag = 1
				count = min(count, parent[1])
			level = parent[1] + 1
			for item in self.graph[parent[0]]:
				if item not in visited:
					queue.append([item, level])
					visited.add(item)
		return count if flag else -1
		return False

class Tree:

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

def inorder(node, lis):
	if node:
		inorder(node.left, lis)
		lis.append(node.data)
		inorder(node.right, lis)
	return lis

def leaf_node_sum(root):
	if root is None:
		return 0
	if root.left is None and root.right is None:
		return root.data
	return leaf_node_sum(root.left) + leaf_node_sum(root.right)

def hight(root):
	if root is None:
		return -1
	if root.left is None and root.right is None:
		return 0
	return max(hight(root.left), hight(root.right)) + 1

class UF:

	def __init__(self, N):
		self._id = list(range(N))
		self._count = N
		self._rank = [0] * N

	def find(self, p):
		id = self._id
		while p != id[p]:
			p = id[p]
		return p

	def count(self):
		return self._count

	def connected(self, p, q):
		return self.find(p) == self.find(q)

	def union(self, p, q):
		id = self._id
		rank = self._rank
		i = self.find(p)
		j = self.find(q)
		if i == j:
			return
		self._count -= 1
		if rank[i] < rank[j]:
			id[i] = j
		elif rank[i] > rank[j]:
			id[j] = i
		else:
			id[j] = i
			rank[i] += 1

	def add_roads(self):
		return set(self._id)

	def __str__(self):
		return ' '.join([str(x) for x in self._id])

	def __repr__(self):
		return 'UF(' + str(self) + ')'

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

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

def p_sum(array):
	return list(itertools.accumulate(array))

def base_change(nn, bb):
	if nn == 0:
		return [0]
	digits = []
	while nn:
		digits.append(int(nn % bb))
		nn //= bb
	return digits[::-1]

def diophantine(a: int, b: int, c: int):
	(d, x, y) = extended_gcd(a, b)
	r = c // d
	return (r * x, r * y)

@bootstrap
def extended_gcd(a: int, b: int):
	if b == 0:
		(d, x, y) = (a, 1, 0)
	else:
		(d, p, q) = (yield extended_gcd(b, a % b))
		x = q
		y = p - q * (a // b)
	yield (d, x, y)
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, **kwargs):
		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 inp():
	return sys.stdin.readline().strip()

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))
for _ in range(int(inp())):
	n = int(inp())
	arr = list_inp(int)
	ans = 0
	for i in range(n):
		if arr[i] - (i + 1) > 0:
			ans = max(ans, arr[i] - (i + 1))
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(el) for el in input().split(' ')]
	res = 0
	for (j, el) in enumerate(arr):
		res += max([0, el - j - 1 - res])
	print(res)


for _ in range(int(input())):
	n = int(input())
	L = [int(l) for l in input().split()]
	de = 0
	for i in range(len(L)):
		de = max(de, L[i] - i)
	print(de - 1)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	m = []
	for j in range(1, n + 1):
		m.append(a[j - 1] - j)
	print(max(m))


n = int(input())
for _ in range(n):
	m = int(input())
	s = [int(z) for z in input().split()]
	s.insert(0, -1)
	count = 0
	for j in range(1, m + 1):
		if j + count < s[j]:
			count = count + s[j] - j - count
	print(count)


t = int(input())
answers = list()
for i in range(t):
	n = int(input())
	mas = list(map(int, input().split()))
	ans = 0
	for j in range(n):
		if mas[j] - (j + 1) > ans:
			ans = mas[j] - (j + 1)
	answers.append(ans)
print('\n'.join(map(str, answers)))


from collections import Counter, defaultdict, OrderedDict, deque
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from typing import List
import itertools
import math
import heapq
import string
import random
(MIN, MAX, MOD) = (-1061109567, 1061109567, 1000000007)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

def N():
	return int(input())
for _ in range(N()):
	n = N()
	a = RLL()
	ans = 0
	for i in range(n):
		ans = max(ans, a[i] - i - 1)
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = [0] + [*map(int, input().split())]
	print(max((l[i] - i for i in range(1, n + 1))))


def solve(arr, n):
	temp = 0
	for i in range(1, n + 1):
		x = arr[i - 1] - temp
		if x > i:
			temp += x - i
	return temp
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(arr, n))


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


for s in [*open(0)][2::2]:
	print(max((int(x) - i - 1 for (i, x) in enumerate(s.split()))))


for cases in range(int(input())):
	len_of_seq = int(input())
	elements_of_seq = list(map(int, input().split()))
	answer = 0
	for i in range(len_of_seq):
		if elements_of_seq[i] <= i + 1 + answer:
			continue
		else:
			answer += elements_of_seq[i] - (i + 1 + answer)
	print(answer)


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

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

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

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	cnt = 0
	for i in range(1, n + 1):
		if a[i - 1] > i + cnt:
			cnt += max(0, a[i - 1] - i - cnt)
	print(cnt)


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


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
a = []
(n, k) = (0, 0)
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07
x = 0
pref = []
lvl = []

def update_it(bit, i, val):
	n = len(bit)
	while i < n:
		bit[i] += val
		i += i & -i

def get_ans(bit, i):
	n = len(bit)
	tot = 0
	while i > 0:
		tot += bit[i]
		i -= i & -i
	return tot

def hnbhai(tc):
	n = sb()
	a = sd()
	x = 0
	tot = 0
	for i in range(n):
		if i + x + 1 < a[i]:
			x += a[i] - i - x - 1
	print(x)
	return
for _ in range(sb()):
	hnbhai(_ + 1)


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


t = int(input())
for q in range(0, t):
	n = int(input())
	arr = list(map(int, input().split()))
	res = arr[0] - 1
	for i in range(1, n):
		if arr[i] <= arr[i - 1]:
			arr[i] = arr[i - 1] + 1
		else:
			res += arr[i] - arr[i - 1] - 1
	print(res)


def main():
	t = int(input())
	for test in range(t):
		n = int(input())
		a = [int(i) for i in input().split()]
		m = 0
		for i in range(n):
			m = max(a[i] - i - 1, m)
		print(m)
main()


t = int(input())
while t > 0:
	n = int(input())
	ar = list(map(int, input().split()))
	x = 1
	cnt = 0
	for i in range(n):
		if ar[i] > x:
			cnt += ar[i] - x
			x = ar[i] + 1
		else:
			x += 1
	print(cnt)
	t -= 1


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


import sys
inp = sys.stdin.readline

def solve():
	n = int(inp())
	a = list(map(int, inp().split()))
	r = 0
	for i in range(n):
		r = max(r, a[i] - (i + 1))
	print(r)

def main():
	for i in range(int(inp())):
		solve()
main()


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	mx = 0
	for i in range(n):
		mx = max(mx, arr[i] - i - 1)
	print(mx)


for i in range(int(input())):
	n = int(input())
	A = [int(k) for k in input().split()]
	b = 0
	for k in range(n):
		if A[k] > b + k + 1:
			b = A[k] - k - 1
	print(b)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	res = 0
	index = 1
	for i in range(n):
		if a[i] > index:
			res += a[i] - index
			index = a[i]
		index += 1
	print(res)


for _ in range(int(input())):
	n = int(input())
	w = [int(i) for i in input().split()]
	a = 0
	for i in range(0, n):
		if w[i] - (i + 1) > a:
			a = w[i] - (i + 1)
	print(a)


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


import sys
input = sys.stdin.readline

def print(*args, end='\n', sep=' ') -> None:
	sys.stdout.write(sep.join(map(str, args)) + end)

def solve() -> None:
	input()
	ans = 0
	for (i, x) in enumerate(map(int, input().split())):
		ans = max(ans, x - i - 1)
	print(ans)

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


import sys, math

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	ans = 0
	for i in range(1, len(l) + 1):
		ans = max(ans, l[i - 1] - i)
	print(ans)
t = int(input())
while t != 0:
	solve()
	t -= 1


for i in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	x = sorted(A)
	edx = 0
	for i in x:
		pos = A.index(i) + 1
		if pos + edx < i:
			edx += i - pos - edx
	print(edx)


from math import gcd, sqrt
from sys import stdin, stdout
from collections import Counter, deque
from bisect import bisect_left, bisect_right
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	for i in range(len(l)):
		if l[i] > i + count:
			count += l[i] - i - count - 1
	print(count)


T = int(input())
for i in range(T):
	N = int(input())
	arr = list(map(int, input().split()))
	m = 0
	for i in range(len(arr)):
		m = max(m, arr[i] - i - 1)
	print(m)


t = int(input())
n = []
sequence = []
for i in range(t):
	n.append(int(input()))
	sequence.append(input())
for i in range(t):
	nums = sequence[i].split()
	max = int(nums[0])
	pos = 0
	for j in range(1, n[i]):
		if int(nums[j]) - j > max:
			max = int(nums[j]) - j
			pos = j
	num = max - 1
	if num <= 0:
		print('0')
	else:
		print(num)


from time import sleep as sle
from math import *
from random import randint as ri

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

def pr(x):
	print()
	for s in x:
		print(s)

def solve():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = [int(q) for q in input().split()]
		ans = 0
		for i in range(n):
			if a[i] > i + 1:
				ans = max(ans, a[i] - i - 1)
		print(ans)
solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	maxi = 0
	for i in range(n):
		maxi = max(maxi, a[i] - i + 1)
	print(maxi - 2)


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


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	maxi = 0
	for j in range(len(a)):
		maxi = max(maxi, a[j] - 1 - j)
	print(maxi)


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	m = 0
	for i in range(len(arr)):
		m = max(m, arr[i] - i - 1)
	print(m)


import copy
import math
fin = None
fout = None
uabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
abet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
INF = 10 ** 18

def start(filename):
	filename = filename.replace('.py', '')
	global fin
	global fout
	infile = filename + '.in'
	outfile = filename + '.out'
	fin = open(infile)
	fout = open(outfile, 'w')

def permutation(lst):
	if len(lst) == 0:
		return []
	if len(lst) == 1:
		return [lst]
	l = []
	for i in range(len(lst)):
		m = lst[i]
		remLst = lst[:i] + lst[i + 1:]
		for p in permutation(remLst):
			l.append([m] + p)
	return l

def subsets(x):
	retset = []
	if len(x) == 0:
		retset = [[]]
	else:
		first = x[-1]
		cop = x.copy()
		cop.remove(first)
		y = subsets(cop)
		retset.extend(copy.deepcopy(y))
		m = copy.deepcopy(y)
		for i in range(len(y)):
			k = m[0]
			m.remove(k)
			k.append(first)
			m.append(k)
		retset.extend(m.copy())
	return retset

class Point:

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

	def __str__(self):
		return str(self.x) + str(self.y)

	def __hash__(self):
		return hash(str(self))

	def __eq__(self, other):
		return self.x == other.x and self.y == other.y

class frac:

	def __init__(self, n, d):
		self.n = n
		self.d = d

	def __str__(self):
		return str(self.n) + '/' + str(self.d)

	def __hash__(self):
		return hash(str(self))

	def simp(self):
		div = math.gcd(self.n, self.d)
		self.n = self.n / div
		self.d = self.d / div

	def __eq__(self, other):
		return self.n / self.d == other.n / other.d

	def __lt__(self, other):
		return self.n / self.d < other.n / other.d

class Interval:

	def __init__(self, start, end):
		self.start = start
		self.end = end

	def __str__(self):
		return str(self.start) + str(self.end)

	def __hash__(self):
		return hash(str(self))

	def __eq__(self, other):
		return self.start == other.start and self.end == other.end

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

def overlap(verl1, verl2):
	if verl1.end >= verl2.start:
		return True
	else:
		return False

def merge(verl1, verl2):
	retverl = Interval(min(verl1.start, verl2.start), max(verl1.end, verl2.end))
	return retverl

def changeBase(num, base):
	if base == 2:
		return '{0:b}'.format(num)
	power = math.floor(math.log(num, base))
	remainder = num
	end = []
	iter = list(range(power + 1))
	iter.reverse()
	for i in iter:
		if remainder >= base ** i:
			(q, r) = divmod(remainder, base ** i)
			end.append(q)
			remainder = r
		else:
			end.append(0)
	retlist = []
	for i in end:
		if i > 9:
			retlist.append(uabet[i - 10])
		else:
			retlist.append(i)
	retlist = map(str, retlist)
	return ''.join(retlist)

def prime(num):
	if num == 2:
		return True
	if num % 2 == 0:
		return False
	for i in range(2, math.ceil(num ** 0.5) + 1):
		if num % i == 0:
			return False
	return True

def solve(n, a):
	t = 0
	for i in range(n):
		if a[i] - (i + 1 + t) > 0:
			t += a[i] - (i + 1 + t)
	return t

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


def main():
	for t in range(int(input())):
		N = int(input())
		arr = tuple(map(int, input().split()))
		ans = 0
		i = 1
		for x in arr:
			if i < x:
				ans += x - i
				i = x + 1
			else:
				i += 1
		print(ans)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	offset = 0
	for (i, num) in enumerate(arr):
		size = i + 1 + offset
		if num > size:
			offset += num - size
	print(offset)


for _ in range(int(input())):
	input()
	A = [int(x) for x in input().split()]
	print(max((a - i for (i, a) in enumerate(A, 1))))


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from heapq import heappush, heappop, heapify
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from math import *
from re import *
from os import *
from operator import truediv

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))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

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

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

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

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

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

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

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

def getPrimes(N=10 ** 5):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
num = getInt()
for _ in range(num):
	n = getInt()
	arr = [0] + zzz()
	ans = 0
	for i in range(1, n + 1):
		x = arr[i]
		if i + ans < x:
			ans += x - (i + ans)
	print(ans)


n = int(input())
for i in range(n):
	count = 0
	k = 0
	lench = int(input())
	chisla = list(map(int, input().split()))
	for l in range(lench):
		k += 1
		if chisla[l] > k:
			count += chisla[l] - k
			k += chisla[l] - k
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	li = []
	for i in range(n):
		li.append(a[i] - (i + 1))
	print(max(li))


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


testCases = int(input())
for i in range(testCases):
	n = int(input())
	temp = [int(x) for x in input().split()]
	operations = 0
	index = 1
	for j in temp:
		if j > index:
			operations += abs(j - index)
			index += abs(j - index)
		index += 1
	print(operations)


import math
import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192
from bisect import bisect_left
from bisect import bisect_right

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def ceil(a, b):
	if a <= 0:
		return 0
	if a % b == 0:
		return a // b
	else:
		return a // b + 1
t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		ans = max(ans, b[i] - (i + 1))
	print(ans)


def solve(arr):
	maximal = 0
	for i in range(len(arr)):
		maximal = max(maximal, arr[i] - i)
	return maximal - 1
T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(arr))


for _ in range(int(input())):
	_ = input()
	arr = list(map(int, input().split()))
	steps = 0
	for i in range(len(arr)):
		if arr[i] <= i + 1 + steps:
			continue
		else:
			steps += arr[i] - (i + 1 + steps)
	print(steps)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = l.copy()
	s.sort()
	c = []
	c = []
	op = 0
	for i in range(n):
		c.append(l[i] - (i + 1))
	print(max(c))


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	ans = 0
	now = 1
	for i in A:
		if now < i:
			ans += i - now
			now = i + 1
		else:
			now += 1
	print(ans)


def calculate(n, l):
	c = 0
	for i in range(1, n + 1):
		if i + c < l[i - 1]:
			c = c + l[i - 1] - i - c
	return c
for _ in range(int(input())):
	print(calculate(int(input()), list(map(int, input().split()))))


p = int(input())
for _ in range(p):
	n = int(input())
	aaa = [0] + list(map(int, input().split()))
	s = 0
	for i in range(1, n + 1):
		a = aaa[i]
		if a <= s + i:
			continue
		s += a - (s + i)
	print(s)


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


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


def func():
	n = int(input())
	l = list(map(int, input().split()))
	mx = 0
	for i in range(n):
		mx = max(mx, l[i] - i - 1)
	return mx
t = int(input())
for i in range(t):
	print(func())


t = int(input())

def put(i):
	if i not in l2:
		l2.append(i)
	else:
		put(i + 1)
for boomer in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	ideal = 0
	for i in range(n):
		if l[i] > ideal:
			ideal = l[i]
		else:
			ideal += 1
	print(ideal - n)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	index = 1
	for j in a:
		if index < j:
			ans += j - index
			index += j - index
		index += 1
	print(ans)


import math

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


def main():
	for t in range(int(input())):
		n = map(int, input().split())
		arr = list(map(int, input().split()))
		total = 0
		for (i, j) in enumerate(arr, start=1):
			total += max(0, j - i - total)
		print(total)
main()


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		l = tuple(map(int, input().split()))
		acc = 0
		for i in range(n):
			aux = l[i] - (i + 1 + acc)
			if aux > 0:
				acc += aux
		print(acc)
main()


tests = input()
for test in range(int(tests)):
	n = int(input())
	b = [int(x) for x in input().split()]
	print(max((b[x] - x - 1 for x in range(len(b)))))


for _ in range(int(input())):
	size = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	for ind in range(size):
		if arr[ind] > ind + 1 + ans:
			ans += arr[ind] - (ind + 1 + ans)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	rr = list(map(int, input().split()))
	a = max([rr[i] - 1 - i for i in range(n)])
	print(a)


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


i = input()
for _ in range(int(i)):
	n = int(input())
	l = map(int, input().split(' '))
	z = 0
	for (i, m) in enumerate(l):
		if m > i + 1:
			z1 = max(m - i - 1, 0)
			if z1 > z:
				z = z1
	print(z)


n = 0
t = 0
N = []
t = int(input())
for w in range(t):
	n = int(input())
	N = list(map(int, input().split()))
	counter = 0
	minus = 0
	old = 0
	for i in range(n):
		if N[i] > old + minus:
			counter += N[i] - old - 1 - minus
			minus = 0
			old = N[i]
		else:
			minus += 1
	print(counter)


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


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, functools, copy
inf = float('inf')
mod = 10 ** 9 + 7

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

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

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

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

def S():
	return input()

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

def endl():
	return print('\n')

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

def grayCode(n):
	return n ^ n >> 1
sys.setrecursionlimit(20000)
graph = collections.defaultdict(list)
grid = []
visited = set()
ways = ['D', 'U', 'R', 'L']
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]

def initGraph(m):
	for _ in range(m):
		(u, v) = LI()
		graph[u - 1].append(v - 1)
		graph[v - 1].append(u - 1)

def initGraphW(m):
	for _ in range(m):
		(a, b, c) = LI()
		graph[a - 1].append((b - 1, c))
		graph[b - 1].append((a - 1, c))

def initGrid(h, w):
	for i in range(h):
		s = S()
		grid.append(list(s))
	return grid

def soe(limit):
	a = [True] * limit
	a[0] = a[1] = False
	for (i, isprime) in enumerate(a):
		if isprime:
			yield i
			for n in range(i * i, limit, i):
				a[n] = False
	return a
for _ in range(I()):
	n = I()
	a = LI()
	ans = 0
	for i in range(n):
		if a[i] > i + 1:
			ans = max(ans, abs(i + 1 - a[i]))
	print(ans)


import os
import sys
from io import BytesIO, IOBase
_str = str
str = lambda x=b'': x if type(x) is bytes else _str(x).encode()
BUFSIZE = 8192

def sigma1(a):
	return sum(a)

def sigma2(a):
	return sum([i * i for i in a])

def sigma3(a):
	return sum([i * i * i for i in a])

def prodofpairs(a):
	return (sigma1(a) ** 2 - sigma2(a)) // 2

def prodoftriplets(a):
	return (sigma1(a) ** 3 - 3 * sigma1(a) * sigma2(a) + 2 * sigma3(a)) // 6
from collections import Counter, defaultdict
from math import gcd
from collections import deque

def bfs(graph, start=0):
	used = [False] * len(graph)
	used[start] = True
	q = [start]
	for v in q:
		for w in graph[v]:
			if not used[w]:
				used[w] = True
				q.append(w)

def layers(graph, start=0):
	used = [False] * len(graph)
	used[start] = True
	(q, ret) = ([start], [])
	level = [0] * len(graph)
	while q:
		nq = []
		ret.append(q)
		for v in q:
			for w in graph[v]:
				if not used[w]:
					used[w] = True
					nq.append(w)
					level[w] = 1 + level[v]
		q = nq
	return level
import math

def findMaxGCD(arr, n, k):
	high = max(arr)
	divisors = [0] * (high + 1)
	for i in range(n):
		for j in range(1, int(math.sqrt(arr[i])) + 1):
			if arr[i] % j == 0:
				divisors[j] += 1
				if j != arr[i] // j:
					divisors[arr[i] // j] += 1
	for i in range(high, 0, -1):
		if divisors[i] >= k:
			return i

def xdist(a, b):
	if b[0] >= a[0] >= b[2] or b[0] <= a[0] <= b[2]:
		return 0
	return min(abs(a[0] - b[0]), abs(a[0] - b[2]))

def ydist(a, b):
	if b[1] >= a[1] >= b[3] or b[1] <= a[1] <= b[3]:
		return 0
	return min(abs(a[1] - b[1]), abs(a[1] - b[3]))

def countdistx(i, j, k, obj):
	m = 0
	for i1 in range(k):
		m += xdist([i, j], obj[i1])
	return m

def countdisty(i, j, k, obj):
	m = 0
	for i1 in range(k):
		m += ydist([i, j], obj[i1])
	return m
from bisect import bisect_left

def dp(i, n, cost, a):
	if cost == 0:
		return 0
	if cost < 0:
		return float('Inf')
	l = [float('Inf')]
	for j in range(i, n + 1):
		k = bisect_left(a, a[j] + cost, j)
		if k <= n and a[k] == a[j] + cost:
			l.append(k - j)
	return min(l)

def isp(x):
	for i in range(2, int(math.sqrt(x)) + 1):
		if x % i == 0:
			return False
	return True
from bisect import bisect_right
from sys import stdout
from math import ceil, log2, floor

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		ans = 0
		for i in range(n):
			ans = max(ans, a[i] - i - 1)
		print(ans)
main()

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


for test in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	maxi = -1
	for i in range(len(arr)):
		if arr[i] >= i + 1:
			maxi = max(maxi, arr[i] - (i + 1))
	print(maxi)


testCases = int(input())
answers = []

def testCase():
	numIntegers = int(input())
	numbers = input().split(' ')
	for (i, str) in enumerate(numbers):
		numbers[i] = int(str)
	operations = 0
	for (i, num) in enumerate(numbers):
		if num > i + 1 + operations:
			operations += num - (i + 1 + operations)
	answers.append(operations)
for _ in range(testCases):
	testCase()
for answer in answers:
	print(answer)


def solve(arr):
	cnt = 0
	for i in range(len(arr)):
		cnt = max(cnt, arr[i] - i)
	return cnt - 1
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = [int(a) for a in input().split()]
	print(solve(arr))


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	r = 0
	for i in range(n):
		r = max(r, s[i] - i - 1)
	print(r)


for _ in range(int(input())):
	n = int(input())
	input_arr = list(map(int, input().split()))
	res = 0
	for i in range(len(input_arr)):
		if i + 1 < input_arr[i]:
			pio = abs(input_arr[i] - (i + 1))
			if pio > res:
				res = pio
	print(res)


for _ in range(int(input())):
	n = int(input())
	ans = []
	l = list(map(int, input().split()))
	for i in range(len(l)):
		if l[i] > i:
			ans.append(l[i] - (l.index(l[i]) + 1))
	print(max(ans))


for i in range(int(input())):
	n = int(input())
	numbers = list(map(int, input().split()))
	sum = 0
	for i in range(len(numbers)):
		sum = max(sum, numbers[i] - (i + 1))
	print(sum)


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	ans = 0
	xd = 1
	for i in range(n):
		if x[i] > xd:
			ans += x[i] - xd
			xd = x[i] + 1
		else:
			xd += 1
	print(ans)


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


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	i = 1
	s = len(x)
	for a in x:
		if a > i:
			b = a - i
			i += b + 1
			s += b
		else:
			i += 1
	print(s - len(x))


for _ in range(int(input())):
	n = int(input())
	ms = list(map(int, input().split()))
	answer = 0
	now = 1
	delta = 0
	for i in range(n):
		if now >= ms[i]:
			now += 1
		else:
			delta = ms[i] - now
			answer += delta
			now += delta + 1
	print(answer)


t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	count = 0
	i = 0
	j = 1
	while i < n:
		if l[i] > j:
			c = l[i] - j
			count += c
			j = j + c + 1
		else:
			j += 1
		i += 1
	print(count)


t = int(input())
for c in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	mx_diff = 0
	for (idx, item) in enumerate(a):
		if item - idx > mx_diff:
			mx_diff = item - idx - 1
	print(mx_diff)


import math
from sys import stdin
from collections import Counter, deque
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	ad = 0
	for i in range(n):
		if a[i] > i + 1 + ad:
			ad = ad + (a[i] - (i + ad) - 1)
	print(ad)


t = int(input())
z = []
for i in range(t):
	n = int(input())
	a = [int(s) for s in input().split(' ')]
	z.append(a)
for i in range(t):
	k = z[i]
	for j in range(len(k)):
		k[j] -= j + 1
	print(max(k))


in1 = int(input())
for i in range(in1):
	in2 = int(input())
	in3 = input().split()
	in3 = list(map(int, in3))
	j = 0
	k = 0
	o = 0
	while j < in2:
		if in3[j] > k + 1:
			o += in3[j] - (k + 1)
			k += in3[j] - (k + 1)
		j += 1
		k += 1
	print(o)


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		N = int(input())
		A = list(map(int, input().split()))
		(ans, i) = (0, 1)
		for a in A:
			if a > i:
				ans += a - i
				i = a
			i += 1
		print(ans)
main()


t = int(input())
for i in range(t):
	n = int(input())
	sum = 0
	lt = list(map(int, input().split()))
	for j in range(0, n):
		if lt[j] > j + 1 + sum:
			temp = lt[j] - (j + 1 + sum)
			sum += temp
	print(sum)


for _ in range(int(input())):
	l = int(input())
	arr = list(map(int, input().split()))
	count = 0
	for i in range(l):
		if arr[i] > i + 1:
			if i == 0:
				count += arr[i] - 1
			elif arr[i] > i + 1 + count:
				temp = arr[i] - count - i
				count += temp - 1
	print(count)


def foo():
	n = int(input())
	a = [int(i) for i in input().split()]
	ans = 0
	for i in range(n):
		if a[i] > i + 1 + ans:
			ans += a[i] - i - 1 - ans
	print(ans)
t = int(input())
for _ in range(t):
	foo()


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


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


n = int(input())
arr = []
for x in range(n):
	k = int(input())
	arr_list = [int(x) for x in input().split()]
	arr.append(arr_list)
for x in arr:
	new_x = [y - num for (num, y) in enumerate(x, start=1) if y - num > 0]
	if bool(new_x):
		print(max(new_x))
	else:
		print(0)


def solve(arr):
	s = 0
	i = 1
	for val in arr:
		if val >= i:
			d = val - i
			s += d
			i += d
		i += 1
	return s
for _ in '_' * int(input()):
	input()
	print(solve([*map(int, input().split())]))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	for i in range(1, n + 1):
		if a[i - 1] <= i + count:
			continue
		count += a[i - 1] - (i + count)
	print(count)


for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ans = 0
	kek = 1
	for elem in ar:
		if elem > kek:
			ans += elem - kek
			kek = elem
		kek += 1
	print(ans)


import math
from collections import defaultdict, Counter
from bisect import bisect_left
from sys import stdin
from math import gcd
from functools import reduce
import itertools

def find():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if a[i] <= i + ans + 1:
			continue
		else:
			ans = a[i] - i - 1
	print(ans)
input = stdin.readline
t = int(input())
for _ in range(t):
	find()


import sys
IS_INTERACTIVE = False
input = input
if not IS_INTERACTIVE:
	(*data,) = sys.stdin.read().split('\n')[::-1]

	def input():
		return data.pop()

def fprint(*args, **kwargs):
	print(*args, **kwargs, flush=True)

def eprint(*args, **kwargs):
	print(*args, **kwargs, file=sys.stderr)
for _ in range(int(input())):
	n = int(input())
	(*arr,) = map(int, input().split())
	cnt = 0
	mx = max((v - i for (i, v) in enumerate(arr, 1)))
	print(mx)


import sys, math
input = sys.stdin.readline
n = int(input())
for i in range(n):
	x = int(input())
	l = list(map(int, input().split()))
	ans = 0
	for i in range(x):
		if l[i] > i + ans:
			ans += l[i] - i - ans
	print(ans - 1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	maxDiff = 0
	for i in range(1, len(a) + 1):
		diff = a[i - 1] - i
		if diff > 0 and diff > maxDiff:
			maxDiff = diff
	print(maxDiff)


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	e = 1
	ans = 0
	for a in arr:
		if a > e:
			ans += a - e
			e = a + 1
		else:
			e += 1
	print(ans)


t = int(input())
for qwer in range(t):
	n = int(input())
	stro = list(map(int, input().split()))
	sp = stro
	i = 1
	s = 0
	while i <= len(stro):
		if i == 1 and i < stro[0]:
			s += stro[0] - 1
		elif i < stro[i - 1] - s:
			s += stro[i - 1] - i - s
		i += 1
	print(s)


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = 0
	for i in range(n):
		if a[i] >= i + 1:
			ans = max(ans, a[i] - 1 - i)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(s) for s in input().split()]
	j = 0
	for i in range(n):
		if j < a[i]:
			j = a[i]
		else:
			j += 1
	print(j - n)


from sys import stdin
from collections import deque
lst = list(map(int, stdin.read().split()))
_s = 0

def inp(n=1):
	global _s
	ret = lst[_s:_s + n]
	_s += n
	return ret

def inp1():
	return inp()[0]
t = inp1()
for _ in range(t):
	n = inp1()
	a = inp(n)
	mx = 0
	for i in range(1, n + 1):
		dif = a[i - 1] - i
		if dif > 0:
			mx = max(mx, dif)
	print(mx)


t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	c = -1000
	for i in range(len(l)):
		c = max(c, l[i] - (i + 1))
	print(c)


for test in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	print(max((a[i] - i - 1 for i in range(len(a)))))


t = int(input())
p = []
for i in range(t):
	ans = 0
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(len(l)):
		j = i + 1
		if l[i] > j + ans:
			k = l[i] - (j + ans)
			ans += k
	p.append(ans)
print(*p, sep='\n')


for inh in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(0, n):
		ans = max(ans, a[i] - i - 1)
	print(ans)


t = int(input())
for case in range(t):
	size = int(input())
	arr = map(int, input().split())
	base_1_index = 1
	total = 0
	for num in arr:
		if num > base_1_index:
			total += num - base_1_index
			base_1_index = num + 1
		else:
			base_1_index += 1
	print(total)


import math
t = int(input())
for tc in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	j = 0
	for i in range(n):
		if arr[i] > j + 1:
			ans += arr[i] - j - 1
			j += arr[i] - j - 1
		j += 1
	print(ans)


import sys
from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	ans = 0
	for i in range(n):
		c += max(0, a[i] - (i + 1 + c))
	print(c)


mod = 10000000
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	for i in range(n):
		if a[i] > c + i + 1:
			c = c + (a[i] - i - 1 - c)
	print(c)


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		s = input().split()
		a = [int(s[i]) for i in range(n)]
		added = 0
		for j in range(n):
			if 1 + j + added < a[j]:
				added += a[j] - 1 - j - added
		print(added)
main()


import sys
import math
import collections
import heapq
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]
r = lambda : sys.stdin.readline().rstrip()
MIS = lambda : map(int, r().split())
for _ in range(int(r())):
	N = int(r())
	L = list(MIS())
	ans = 0
	for i in range(N):
		ans = max(ans, L[i] - i - 1)
	print(ans)


def era(n, a):
	max_diff = 0
	for (i, ai) in enumerate(a, 1):
		diff = ai - i
		if diff > max_diff:
			max_diff = diff
	return max_diff
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	print(era(n, a))


T = int(input())
for i in range(T):
	x = int(input())
	y = list(map(int, input().split()))
	for j in range(len(y)):
		y[j] = y[j] - j
	print(max(y) - 1)


t = int(input())
ress = []
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	res = 0
	i = 1
	for el in a:
		if el > i:
			res += el - i
			i = el + 1
		else:
			i += 1
	ress.append(res)
for el in ress:
	print(el)


from sys import stdin, stdout

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

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def MOD():
	return pow(10, 9) + 7

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

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
for _ in range(INI()):
	n = INI()
	X = [0] + INL()
	f = -1
	i = -1
	for _ in range(1, n + 1):
		if X[_] > _:
			f = X[_] - _
			i = _
			break
	if f == -1:
		OPS('0')
	else:
		ans = f
		for _ in range(i + 1, n + 1):
			if X[_] > i:
				t = X[_] - _
				if t > ans:
					ans += t - ans
		OPS(ans)