Problem: For an array of length , define as the sum of the minimum element over all subsegments. That is,
A permutation is a sequence of integers from to of length containing each number exactly once. You are given a permutation . For each , solve the following problem independently:
- Erase from , concatenating the remaining parts, resulting in .
- Calculate .
Input Format: Each test contains multiple test cases. The first line contains the number of test cases (). Description of the test cases follows.
The first line of each test case contains an integer ().
The second line of each test case contains distinct integers ().
It is guaranteed that the sum of over all test cases does not exceed .
Output Format: For each test case, print one line containing integers. The -th integer should be the answer when erasing .
Note: In the second test case, .
- When removing , . .
- When removing , . .
- When removing , . .