Sales

No attempts yetTime limit1sMemory limit128 MB

Problem

Mr. Cooper, the CEO of CozyWalk Co., receives a report of the day's sales every day since the company was founded. Starting from the second day after its founding, each time he receives a report he compares it with every previous report and counts how many earlier days had sales less than or equal to that day's sales. He then records this count in a list.

More formally, let A=(a1,a2,,an)A = (a_1, a_2, \dots, a_n) be the list of daily sales amounts, and let B=(b1,b2,,bn1)B = (b_1, b_2, \dots, b_{n-1}) be another list of integers kept by Mr. Cooper. On day ii (2in2 \le i \le n) he computes bi1b_{i-1}, the number of indices kk with 1k<i1 \le k < i such that akaia_k \le a_i.

For example, suppose A=(20,43,57,43,20)A = (20, 43, 57, 43, 20). For the fourth day's sales a4=43a_4 = 43, the number of earlier days whose sales are less than or equal to it is 22, because a1a4a_1 \le a_4, a2a4a_2 \le a_4, and a3>a4a_3 > a_4. Hence b3=2b_3 = 2. Computing the remaining values in the same way gives B=(1,2,2,1)B = (1, 2, 2, 1).

Given the list of daily sales of size nn, write a program that prints the sum of the n1n-1 integers in the list BB.

Input

The input is read from standard input. It consists of TT test cases. The first line contains the number of test cases TT. Each test case begins with a line containing an integer nn (2n10002 \le n \le 1000), the size of the list AA. The next line contains nn integers, where each is a daily sales amount aia_i (1ai50001 \le a_i \le 5000, 1in1 \le i \le n) for that test case.

Output

Write to standard output. For each test case, print the sum of the n1n-1 integers in the list BB obtained from the list AA, one value per line.