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) be the list of daily sales amounts, and let B=(b1,b2,…,bn−1) be another list of integers kept by Mr. Cooper. On day i (2≤i≤n) he computes bi−1, the number of indices k with 1≤k<i such that ak≤ai.
For example, suppose A=(20,43,57,43,20). For the fourth day's sales a4=43, the number of earlier days whose sales are less than or equal to it is 2, because a1≤a4, a2≤a4, and a3>a4. Hence b3=2. Computing the remaining values in the same way gives B=(1,2,2,1).
Given the list of daily sales of size n, write a program that prints the sum of the n−1 integers in the list B.
The input is read from standard input. It consists of T test cases. The first line contains the number of test cases T. Each test case begins with a line containing an integer n (2≤n≤1000), the size of the list A. The next line contains n integers, where each is a daily sales amount ai (1≤ai≤5000, 1≤i≤n) for that test case.
Write to standard output. For each test case, print the sum of the n−1 integers in the list B obtained from the list A, one value per line.