You will be given an array **A** of non negative integers. You can perform a swap operation on any two adjacent elements in the array. Find the minimum number of swaps needed to sort the array in increasing order.

**Input: **

The first line of input contains a single integer **T** denoting the number of test cases.

Then **T** test cases follow. The first line of each test case consists of a positive integer **N **denoting the size of the array. The second line of each test case consists of **N **space separated integers denoting the values in the array **A**.** **

**Output:**

Corresponding to each test case, in a new line, print the minimum number of swaps needed to sort the array in increasing order.

**Constraints:**

1 ≤ **T** ≤ 100

1 ≤ **N** ≤ 1000

0 ≤ **A[i]** ≤ 100000

**Example:**

**Input**

2

4

4 1 2 3

4

4 4 2 3

**Output**

3

4

**Explanation**:

1) (4,1,2,3) --> (1,4,2,3) --> (1,2,4,3) --> (1,2,3,4). Hence we need a total of 3 swaps to sort it in increasing order.

2) (4,4,2,3) --> (4,2,4,3) -->(4,2,3,4) --> (2,4,3,4) --> (2,3,4,4,). Hence we need a total of 4 swap to sort it in increasing order.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

jhasaurabh312 | 138 |

Aaaaarohiiii | 136 |

Harsha_kunchala | 128 |

tushki | 124 |

RajaRajput | 117 |

ARUN_PUNDIR | 617 |

manishgupta8497 | 607 |

Abhimanyu_kumar | 559 |

KhyatiSoneji | 501 |

Aman___Jain | 496 |

blackshadows | 5335 |

Ibrahim Nash | 5223 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.