Associated Course(s):
Geeks Classes
Geeks Classes- Algorithms

You are given an array of positive integer numbers a1,a2...aN.

Count number of pairs (i,j) such that:

1≤ i ≤ N

1≤ j ≤ N

ai < aj

**Input:**

The first line contains 'T' denoting the number of test cases. Then follows description of testcases.Each case begins with a single positive integer N denoting the size of array.The second line contains N space separated positive integers denoting the elements of array.

**Output:**

For each test case, output a single line containing number of pairs for corresponding test case.

**Constraints:**

1<=T<=20

1<=N<=10^3

1<=a[i]<=10^3

**Example:**

Input :

2

2

2 1

3

2 3 2

Output :

1

2

**Explanation:**

In the first test case, the only good pair is (2,1).

In the second test case, the two good pairs are (2,3) and (3,2).

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.

saiujwal13083 | 347 |

isiddhisingh | 252 |

Abhishek_Jadhav | 243 |

_uncle_sam_ | 221 |

c_ocoooo | 217 |

saiujwal13083 | 610 |

SumitSingh27 | 466 |

c_ocoooo | 456 |

rathiarpit29 | 379 |

NaveenKumarNakka | 370 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4931 |

Quandray | 4598 |

Login to report an issue on this page.