Water Pump

Place one pump in a cell, let water drain toward it from both sides, and find the cell that removes the most water.

Medium5ArrayPrefix sumInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

NN walls stand in a line from west to east, numbered 11 to NN starting at the west end. Wall ii is hih_i units tall. A wall lets no water through, its thickness is 00, and every wall stands on flat ground at height 00.

Wall ii and wall i+1i+1 enclose a space of width 11. That space is cell ii, and the city has N1N-1 cells. One unit of water fills one cell to a depth of 11, so a cell whose water level is dd holds dd units of water.

Heavy rain floods the city. Water crosses a wall once its level rises above the top of that wall, and water that crosses west of wall 11 or east of wall NN leaves the city. After the rain stops, the water level in cell ii is

min(max1aiha,  maxi+1bNhb)\min\left(\max_{1 \le a \le i} h_a,\; \max_{i+1 \le b \le N} h_b\right)

The governor picks one cell and puts a pump in cell pp. The pump removes all water from cell pp and keeps removing whatever flows in. While the level in a cell is above the wall it shares with a neighboring cell, water crosses that wall into the neighbor, so water from distant cells can reach the pump. Pumping ends when no more water flows into cell pp.

Pick pp so that the pump removes as much water as possible, and print how many units it removes. When N=1N = 1 there is no cell, so the answer is 00.

Input

The first line has an integer TT, the number of test cases. (1T201 \le T \le 20)

Each test case takes two lines. The first line has NN, the number of walls. (1N100,0001 \le N \le 100{,}000) The second line has the wall heights h1,h2,,hNh_1, h_2, \dots, h_N separated by spaces, where hih_i is the height of wall ii. (0hi10,0000 \le h_i \le 10{,}000)

Output

Print TT lines. Line ii holds the answer for the ii-th test case, the largest number of water units a single pump can remove.