You want to build a temple for snakes. The temple will be built on a mountain range, which can be thought of as n blocks, where height of i-th block is given by hi. The temple will be made on a consecutive section of the blocks and its height should start from 1 and increase by exactly 1 each time till some height and then decrease by exactly 1 each time to height 1, 
i.e. a consecutive section of 1, 2, 3, .. x-1, x, x-1, x-2, .., 1 can correspond to a temple. Also, heights of all the blocks other than of the temple should have zero height, so that the temple is visible to people who view it from the left side or right side.
You want to construct a temple. For that, you can reduce the heights of some of the blocks. In a single operation, you can reduce the height of a block by 1 unit. Find out minimum number of operations required to build a temple.

-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer n.
The next line contains n integers, where the i-th integer denotes hi

-----Output-----
For each test case, output a new line with an integer corresponding to the answer of that testcase.

-----Constraints-----
- 1 ≤ T ≤ 10
- 2 ≤ n ≤ 105
- 1 ≤ hi ≤ 109

-----Example-----
Input
3
3
1 2 1
4
1 1 2 1
5
1 2 6 2 1

Output
0
1
3

-----Explanation-----
Example 1. The entire mountain range is already a temple. So, there is no need to make any operation.
Example 2. If you reduce the height of the first block to 0. You get 0 1 2 1. The blocks 1, 2, 1 form a temple. So, the answer is 1.
Example 3. One possible temple can be 1 2 3 2 1. It requires 3 operations to build. This is the minimum amount you have to spend in order to build a temple.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "for tests in range(int(input())):\n n = int(input())\n blockHeights = [int(blockHeight) for blockHeight in input().split()]\n sumOfBlockHeightsBefore = sum(blockHeights)\n blockHeights[0] = blockHeights[n-1] = 1\n\n # make all possible temples and choose biggest one, as its demolition cost \xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0will be heighest\n # carve first half of temples i.e left right angle triangle, considering \xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0temple an equilateral triangle\n for i in range(1, n):\n  if blockHeights[i] > blockHeights[i-1] + 1:\n   blockHeights[i] = blockHeights[i-1] + 1\n\n # carve second half of temples i.e right right angle triangle\n for i in range(n-2, -1, -1):\n  if blockHeights[i] > blockHeights[i+1] + 1:\n   blockHeights[i] = blockHeights[i+1] + 1\n heightOfTallestTemple = max(blockHeights)\n\n # find sum of blocks for height of tallest temple\n # through arithematic progression we have a1= 1, an = heightOfTallestTemple, \xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0d = 1 and thus Sn = (a1 + an) * an / 2\n # so we have to AP series for two halves of temple\n # s1 = (1 + heightOfTallestTemple) * heightOfTallestTemple / 2\n # s2 = (1 + heightOfTallestTemple-1) * (heightOfTallestTemple - 1) / 2\n # s = s1 + s2\n # fruther simplifying we have\n # s = heightOfTallestTemple * heightOfTallestTemple\n s = heightOfTallestTemple ** 2\n\n noOfOperations = sumOfBlockHeightsBefore - s\n # print(blockHeights, heightOfTallestTemple, sum(blockHeights), \xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0sumOfBlockHeightsBefore, s, sep=' | ')\n print(noOfOperations)\n"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13243