Under construction

Still being built. Things may change

Paimon Sorting

Time limit1sMemory limit1024 MB

Summary
For each prefix of a sequence, count how many swaps the bubble-like Sort procedure performs on that prefix.
Level

Medium6 of 10

Topics
Array, Sorting, Math
Solved
No attempts yet

Problem

Paimon has just invented a new sorting algorithm that looks much like bubble sort, with a few differences. It accepts a 1-indexed sequence AA of length nn and sorts it. The pseudo-code is shown below.

Function 1: The Sorting Algorithm

1. function Sort(A)
2.     for i ← 1 to n do // n is the number of elements in A
3.         for j ← 1 to n do
4.             if a_i < a_j then // a_i is the i-th element in A
5.                 Swap a_i and a_j

If you doubt that this algorithm can sort a sequence, prove it. That is part of the task.

Given an integer sequence A=a1,a2,⋯ ,anA = a_1, a_2, \cdots, a_n of length nn, count the number of swaps performed for each prefix AkA_k of length kk, where 1≤k≤n1 \le k \le n and Ak=a1,a2,⋯ ,akA_k = a_1, a_2, \cdots, a_k. That is, count the swaps performed when you call SORT(AkA_k).

Input

There are multiple test cases. The first line contains an integer TT, the number of test cases. Each test case is given as follows.

The first line contains an integer nn (1≤n≤1051 \le n \le 10^5), the length of the sequence.

The second line contains nn integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_n (1≤ai≤n1 \le a_i \le n), the sequence.

The sum of nn over all test cases does not exceed 10610^6.

Output

For each test case, output one line containing nn integers s1,s2,⋯ ,sns_1, s_2, \cdots, s_n separated by spaces, where sis_i is the number of swaps performed when you call SORT(AiA_i).

Examples1

  1. Example 1

    Input
    3
    5
    2 3 2 1 5
    3
    1 2 3
    1
    1
    
    Expected output
    0 2 3 5 7
    0 2 4
    0