Chopped Pairs#12439

Chopped Pairs

2 seconds
256 megabytes
Very hard

For an array of size , we say that a pair is iff:

You're given an array of size .

For an integer (1 \le id \le n), we construct the array b_{id} by performing the following algorithm:

  1. Initialize an array of size where all elements are .

  2. Make c_{id} equal to a_1 (set c_{id} = a_1).

  3. Initialize i=2.

  4. Pick the maximum index 1 \le j \le n where c_j = 0, such that making c_j = a_i results in the array with the minimum number of pairs (Note that you need to minimize the number of pairs in the current array after setting c_j = a_i in the final array after the algorithm ends).

  5. Make c_j equal to a_i (set c_j = a_i).

  6. If i=n, end the algorithm, otherwise increase by and go back to step .

b_{id} is equal to the resulting array .

For each 1 \le id \le n, calculate the number of pairs in the array b_{id}.

Input

The first line consists of a single integer (1 \le t \le 5 \cdot 10^5)the number of testcases.

The description of each testcase follows.

The first line of each testcase consists of a single integer (1 \le n \le 5 \cdot 10^5)the size of the array .

The second line contains integers a_1 , a_2 , ... , a_n (1 \le a_i \le n)the elements of the array .

It is guaranteed that the sum of over all testcases does not exceed 5 \cdot 10^5.

Output

For each testcase, output the answer a sequence of space-separated integers.

Examples

Example 1

Loading
Loading

Scoring

Let be the sum of over all testcases.

  • Subtask ( points): a_i \le a_{i-1} for all (1 < i \le n)

  • Subtask ( points): m \le 500

  • Subtask ( points): m \le 1000

  • Subtask ( points): m \le 5000

  • Subtask ( points): m \le 10^5

  • Subtask ( points): No additional constraints