#P1392C. Omkar and Waterslide

Omkar and Waterslide

Description

Omkar is building a waterslide in his water park, and he needs your help to ensure that he does it as efficiently as possible.

Omkar currently has nn supports arranged in a line, the ii-th of which has height aia_i. Omkar wants to build his waterslide from the right to the left, so his supports must be nondecreasing in height in order to support the waterslide. In 11 operation, Omkar can do the following: take any contiguous subsegment of supports which is nondecreasing by heights and add 11 to each of their heights.

Help Omkar find the minimum number of operations he needs to perform to make his supports able to support his waterslide!

An array bb is a subsegment of an array cc if bb can be obtained from cc by deletion of several (possibly zero or all) elements from the beginning and several (possibly zero or all) elements from the end.

An array b1,b2,,bnb_1, b_2, \dots, b_n is called nondecreasing if bibi+1b_i\le b_{i+1} for every ii from 11 to n1n-1.

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1001 \leq t \leq 100). Description of the test cases follows.

The first line of each test case contains an integer nn (1n21051 \leq n \leq 2 \cdot 10^5) — the number of supports Omkar has.

The second line of each test case contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} (0ai109)(0 \leq a_{i} \leq 10^9) — the heights of the supports.

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

For each test case, output a single integer — the minimum number of operations Omkar needs to perform to make his supports able to support his waterslide.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1001 \leq t \leq 100). Description of the test cases follows.

The first line of each test case contains an integer nn (1n21051 \leq n \leq 2 \cdot 10^5) — the number of supports Omkar has.

The second line of each test case contains nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} (0ai109)(0 \leq a_{i} \leq 10^9) — the heights of the supports.

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

Output

For each test case, output a single integer — the minimum number of operations Omkar needs to perform to make his supports able to support his waterslide.

Sample Input 1

3
4
5 3 2 5
5
1 2 3 5 3
3
1 1 1

Sample Output 1

3
2
0

Note

The subarray with which Omkar performs the operation is bolded.

In the first test case:

  • First operation:

    [5,3,2,5][5,3,3,5][5, 3, \textbf{2}, 5] \to [5, 3, \textbf{3}, 5]

  • Second operation:

    [5,3,3,5][5,4,4,5][5, \textbf{3}, \textbf{3}, 5] \to [5, \textbf{4}, \textbf{4}, 5]

  • Third operation:

    [5,4,4,5][5,5,5,5][5, \textbf{4}, \textbf{4}, 5] \to [5, \textbf{5}, \textbf{5}, 5]

In the third test case, the array is already nondecreasing, so Omkar does 00 operations.