Problem A: Insertion Sort Count
Time Limit: 1s
For example, an insertion sort on {20,40,30,10} would produce the following states for R after each step:
20 (first element is inserted at index 0)
20,40 (inserting 40 at index 1 requires no moves)
20,30,40 (30 is inserted at index 1, so 40 has to be moved)
10,20,30,40 (10 is inserted at index 0, so 20, 30 and 40 have to be moved)
In total, 4 moves were needed.
Given A, which contains a sequence of distinct numbers, output the number of moves that would be performed by an insertion sort on A.
Input
Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <= 100) which is the number of test cases. T consecutive test cases follow.
For each case, there is an integer N (1 <= N <= 50), represents the number of elements in A. Then a line containing N integers follows. All the N integers will be between -1000 and 1000, inclusive.
Output
For each test case, output one line with the number of moves that would be performed by an insertion sort on A.
Sample Input
3 4 20 40 30 10 3 -1 1 0 3 -1000 0 1000
Sample Output
4 1 0