题目描述
You need to shuffle a series of numbers from 1 To T, inclusive. The numbers are in ascending order, you have to shuffle them using bubble sort algorithm, that is swap every time a number is greater than another in the given list in the input. A number is greater than another in the list if the number appears later than the other in the list, check example for more clarity.
Print the count of swaps done while you run the algorithm to shuffle them.
Following is the bubble sort algorithm
procedure bubbleSort( A : list of items )
n = length(A)-1
for j=0 to n inclusive do
for i = 0 to n-1 inclusive do
/ if this pair is out of order /
if A[i] > A[i+1] then
/ swap them and remember something changed /
swap( A[i], A[i+1] )
end if
end for
end for
end procedure
Input
Input description.
Input will start will an integer N on newline representing the count of test case. Each case will contain a number T on a newline, representing total count of numbers. Next line of each test case will contain T integers representing the final shuffled series of numbers.
Output
For each test case print the desired output, each on a newline.
Constraints
1 ≤ N ≤ 10
1 ≤ N ≤ 20
Example
Input:
1
3
2 1 3
abac
Output:
1
Explanation
Example case 1. One swap between 1 and 2, because 1 appears later than 2, so 1 is greater than 2.
输入格式
见题面
输出格式
见题面