There are locations in a row, numbered from left to right. Location has height . The sequence is a permutation of the integers from through .
Dadas and Ttas choose two starting locations . Dadas places his piece at , and Ttas places his piece at . They then alternate turns, with Dadas moving first.
When Dadas is currently at and Ttas is currently at , the rules are:
Thus, a piece may move only to a higher location strictly between the two pieces. A move may skip locations, but may not land on or cross the other piece. After each move, use the pieces' current positions to determine which moves are available.
A player who has no legal move on their turn loses. Passing a turn when a legal move exists is not allowed.
For example, let the heights be and the initial positions be . Dadas can move from location , of height , to location , of height . The pieces are now at locations and . There is no location between them, so Ttas cannot move on his turn and Dadas wins.
Both players play optimally to win. Find the number of starting pairs for which Dadas wins, where .
The input is given in the following format.
For each test case, print the number of starting pairs for which Dadas wins on its own line.
In the first test case, the winning starting pairs are and . In both cases, Dadas can move to location , of height , on his first turn, leaving Ttas without a move. For every other starting pair, Dadas has no first move.
The first line contains the number of test cases . Each test case has the following format.
The first line of each test case contains the number of locations .
The second line contains the heights , separated by spaces.
| 3 | 35 |
|
| 4 | 39 | No additional constraints. |
In the second test case, only is winning. Dadas moves from location to location , after which Ttas has no move.
In the third test case, there are no two locations with , so the answer is .
The three winning starting pairs are , , and .
Dadas loses from . His only legal first move is to location , of height . Ttas then moves from location , of height , to location , of height . The only location between the pieces is location , of height , so Dadas has no move on his next turn.