## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Doremy's City Construction Codeforces Solution

C. Doremy's City Construction
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Doremy's new city is under construction! The city can be regarded as a simple undirected graph with $n$ vertices. The $i$-th vertex has altitude ${a}_{i}$. Now Doremy is deciding which pairs of vertices should be connected with edges.

Due to economic reasons, there should be no self-loops or multiple edges in the graph.

Due to safety reasons, there should not be pairwise distinct vertices $u$$v$, and $w$ such that ${a}_{u}\le {a}_{v}\le {a}_{w}$ and the edges $\left(u,v\right)$ and $\left(v,w\right)$ exist.

Under these constraints, Doremy would like to know the maximum possible number of edges in the graph. Can you help her?

Note that the constructed graph is allowed to be disconnected.

Input

The input consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le {10}^{4}$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $n$ ($2\le n\le 2\cdot {10}^{5}$) — the number of vertices.

The second line of each test case contains $n$ integers ${a}_{1},{a}_{2},\dots ,{a}_{n}$ ($1\le {a}_{i}\le {10}^{6}$) — the altitudes of each vertex.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot {10}^{5}$.

Output

For each test case, output the maximum possible number of edges in the graph.