Problem: There are points , each point has a number on it. You're playing a game on them. Initially, you are at point . When you are at point , take following steps:
- If , go to ,
- Otherwise, the game ends.
Before the game begins, you can choose two integers and satisfying , and replace with (set ). Find the number of distinct pairs such that the game that you start after making the change ends in a finite number of steps.
Notice that you do not have to satisfy .
Input Format: Each test contains multiple test cases. The first line contains an integer ( — the number of test cases.
The first line of each test case contains one integer () — the number of points.
The second line contains integers () — the numbers on the axis.
It's guaranteed that the sum of does not exceed .
Output Format: For each test case, print a line containing a single integer — the number of distinct pairs with which the game ends.
Note: In the first test case, the pairs with which the game ends are and , corresponding to the routes and . Note that is invalid since when , violates . is also invalid since you will go from to forever.
In the second test case, the pairs are .
In the fourth test case, the pairs are .