Part 3 of 15 in Sorting  

How many swaps in Bubble sort ? by animeshn

Problem statement

Given a list of integers with no duplicates, find out how many swaps it will take to sort the list in increasing order using Bubble sort.

Input

First line of each test case will contain an integer T = number of test cases. Each test case will contain two lines. First line will contain a number N = no. of elements in the list. Next line will contain N space separated numbers. 1 <= N <= 50.

Output

For each test case, print on a single line, number of swaps required to sort the list in increasing order using Bubble sort.

Sample Input
3
5
2 1 4 6 3
10 
123 21 34 45 25 675 23 44 55 900
1
23
Sample Output
3
16
0
1) You should implement variation of bubble sort in which, the largest element should bubble towards right in each pass over the list. 


To try out your code



Sign in

Sign up