You are given the task to manage students coming to morning prayer in the school. Students having roll numbers 1 to N are coming in an arbitrary manner and you need to make them stand in a queue such that queue is always in ascending order of roll number.
In order to achieve this task, for every incoming student you need to find a student in the queue he will be standing behind (or in front of the queue if no such student is present in the queue ).
For example, if currently, the queue is 1 2 4 and student with roll number 3 arrives, you will have to locate 2 and make 3 stand behind 2.
For each incoming student, find the roll number of student he will be standing behind ( -1 in case no student with roll less than current exists).
Input Format:
The first line of input will contain T, number of test cases.
The first line of each test case will contain N, the number of students.
The second line of each test case will have N distinct space separated numbers denoting the order in which each student is coming.
Output Format:
Output a single number which is the sum of N numbers where ith number denotes answer for ith incoming student.
Answer for each test case should come in a new line.
Input Constraints:
1≤T≤10
1≤N≤105
1≤RollNumber≤N
For the first case
1. Current queue {} , 2 will stand at front so -1.
2. Current queue {2}, 1 will stand at front so -1.
3. Current queue {1,2} 4 will stand behind 2 so 2.
4. Current queue {1,2,4} 3 will stand behind 3 so 2.
so sum is -1 -1 + 2 + 2 = 2