Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Statement : E. It All Went Sideways

E. It All Went Sideways

Yousef has $n$ columns of cubes standing side by side. The $i$-th column contains $a_i$ identical unit cubes stacked vertically. Initially gravity pulls cubes downwards, so every column $i$ contains exactly $a_i$ cubes at heights $1, 2, \dots, a_i$.

Suddenly, gravity shifts to the right. Each cube slides horizontally as far to the right as possible. A cube cannot pass through or overlap other cubes, and it must remain at its original height. The final configuration is uniquely determined by the initial heights.

Before and after applying rightward gravity.

Before the gravity shift, Yousef may perform at most one operation: choose an index $i$ and decrease $a_i$ by $1$ (i.e. remove one cube from that column). He may also choose to do nothing.

A cube is said to move if its column index after the gravity shift is different from its original column index.

Find the maximum possible number of cubes that will move after the gravity shift, assuming Yousef applies the single decrease optimally (or chooses not to apply it).


Input

The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the array.

The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) — the elements of the array.

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


Output

For each test case, output a single integer — the maximum possible number of cubes that will move after the gravity shift, assuming Yousef applies the single decrease optimally (or chooses not to apply it).


Example

Input

5
5
1 2 3 2 1
7
5 4 1 1 1 1 3
6
1 2 3 4 5 6
6
4 1 6 3 2 6
7
1 3 2 7 2 3 1

Output

8
12
0
10
18

Note

Note

In the first test case, it is optimal to perform the operation on index $5$, making the array $a = [1, 2, 3, 2, 0]$. After the gravity shift, every remaining cube will move. The answer is $1+2+3+2 = 8$. It can be proven that a greater answer does not exist.

In the second test case, we can perform the operation on index $6$, making the array $a = [5, 4, 1, 1, 1, 0, 3]$. After the gravity shift, $5+4+1+1+1 = 12$ cubes will move. Note that the cubes at index $7$ do not move, since they are already at the rightmost end of the array.

In the third test case, there is no way to make any cube move.