All \(N\) students of a class are standing on a straight line behind one other student. For example, student 2 is standing behind student 1, student 3 is standing behind student 2, and so on until the \(N^{th}\) student.
The happiness level of a student is determined by the number of students standing before him whose height is strictly greater than him. The total happiness of the class is the sum of the happiness level of all students.
Now you can help minimize this sadness. Your task is to minimize the happiness level of the class.
Note: You can select one student from anywhere in the line and place him at the end of the line.
Input format
- First line: An integer \(T\) denoting the number of test cases
- For each test case:
- First line: An integer \(N\) denoting the number of students in a class
- Next line: \(N\) space-separated integers denoting the height of each student
Output format
For each test case, print the minimum total happiness that can be achived.
Constraints
\(1 \le T \le 5\\ 1 \le N \le 10^5\\ 1 \le height \le 10^{10}\)